Bestcode bcParserPHP 1.6
Bestcode bcParserPHP 1.6 | 31 kB
mathparser.php implements a MathParser class that parses and evaluates math formulas given as strings at runtime. PHP already has an eval() function for similar purposes. However eval() has security problems where a user supplied expression can cause havoc when executed on a web server or elsewhere. bcParserPHP works around this problem by parsing and evaluating the mathematical expression without using eval() function. bcParserPHP is tested with PHP version 5.2.9 and 5.6.8. The library utilizes newer PHP constructs such as classes, constructors, exceptions.
Here is example PHP syntax to use the parser:
include('mathparser/mathparser.php');
$parser = new MathParser();
$parser->setVariable('X', 5);
$parser->setVariable('Y', 2);
$parser->setExpression('COS(X)+SIN(Y)/2');
echo $parser->getValue();
$parser = new MathParser();
$parser->setVariable('X', 5);
$parser->setVariable('Y', 2);
$parser->setExpression('COS(X)+SIN(Y)/2');
echo $parser->getValue();
Math Parser Features At a Glance
Easy to use, simple class API.
Functions with 0 or more known number of parameters in the form of: f(x,y,z)
Functions with unknown number of parameters, e.g. SUM(a,b,c,...)
Comes with predefined functions.
You can create custom functions/variables with callbacks to the functions that you define in your source code.
VariableResolver, a callback function to provide values for undefined variables.
Function/variable names start with letters and can contain letters, numbers and underscore (_).
Expression can contain string literals, variable values and function return values can be strings.
Arithmetic Operators: +, -, /, *, ^, %(mod)
Boolean Operators: , =, &, |, ! ,<>, >=, <=
String concatenation with & or +
Optimization: Constant expression elimination for repeated tasks.
Paranthesis: ( )
List of predefined functions is available in the documentation.
Provides localization support which is a dictionary of message-keys to messages you can set.
Royalty free distribution.
Comes as source code.
Only for V.I.P
Warning! You are not allowed to view this text.