Matex is a PHP Mathematical expression parser and evaluator library. It allows safe execution and calculation of the arbitrary expressions.
Matex can be installed using Composer package manager or manually connected to your project.
Make sure the Composer is installed and your project is properly configured to use Composer tool. Execute in console the following code in order to connect Matex library:
$ composer require madorin/matex
It will adjust the composer.json file of your project by adding Matex library as an requrement.
Check if Composer's /vendor/autoload.php
is included/required in your project.
Download the Matex package and extract it in your project libraries folder.
If you use a custom php autoloader, the classes located in /src/
folder are PSR-4 compatible, so may adjust the autoloader configuration and/or move the folder according to your rules.
For complete manual linking way, include the src/Evaluator.php
in your project:
<?php
require 'path/to/matex/src/Evaluator.php';
Once everything is properly configured, the \Matex\
namespace classes should be available for usage.
The following code should run without any errors and will output 3
as result:
$evaluator = new \Matex\Evaluator();
echo $evaluator->execute('1 + 2');
See examples for code samples.
Matex supports the following operators:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponentiation
% Modulus
Dorin Marcoci - [email protected] - https://www.marcodor.com
Matex is distributed under MIT license.