bcParserObjCTable of ContentsTry Math Parser
Math Parser for PHP

I LOVE PHPMath Parser for PHP

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.

You can view the documentation for Math Parser PHP library here.

Here is an example mathematical expression:

(SIN(X)-SUM(X,Y,Z)/2)^2+5

This example demonstrates the simple expression syntax (which does not look like PHP) and the ability to have user defined functions and variables.

You can test drive Math Parser for PHP online using this PHP page.

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();
 

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.

Here are example expressions to highlight features:

CELL(�F1�)+(X-STRLEN(CELL(�A 1�)+�*�))

String literals, functions, variables and constants are supported. This makes it possible to simulate variables that are not defined ahead of time. For example, you may have a database (or a spreadsheet) that you retrieve values from, but you do not know which table or column the user will use (so you can�t predefine variables with those names). You could allow: LN(X)+VALUE(�MYTABLE�,�MYCOLU MN�) or spreadsheet related expression could look like CELL(�F1�) for example, instead of defining a variable called F1.

SIN(3.14)+5^2+POW(2,MAX(X* 2,Y))
 

Functions, variables, constants can be nested.
Common math functions are defined by default.

2*(LN(1+X) / LOG(1-X))
 

Paranthesis ( ) are supported.

IF(X>0, 3/X, F(X))
 

IF function helps avoid Division By Zero errors as in 3/X.
(3/X will not be evaluated if X>0 is false - parameters to functions are evaluated only if required by the internal logic of a function).

IF(a,b,c) branching function is supported.

Boolean operators are supported. Any non-zero value is TRUE, 0 is FALSE.

Functions can be defined to have 0,1,2,...N numbers of parameters, or unknown number of parameters (whatever the user passes will be the parameters).

 

X+Y/LOG(1+5)
 

If Optimization is turned ON, LOG(1+5) will be optimized away since it is a constant.

VOLUME(HEIGHT, WIDTH, LENGTH)
 

You can create your own functions and variables and name them as you wish.

You can replace a predefined function with your own implementation.

RND()

Functions with 0 parameters are supported.

SUM(1,2,3,4,5,6,...n)

Functions that take unknown number of parameters are supported.

X+COSH(3E-2)

Scientific notation is supported: 3E-2

Using variableResolver Callback

If you know the variables that can be used in the math expression ahead of time, you can use setVariable($name, $value) to set their values.

But sometimes you may not know what variables will be used, and you want to compute their values only if they are used. In that case, you can register a callback function to return the values for variables.

<?php
function variableResolver($parser, $varName) {
    if($varName==('K')){
        return 5; // this is a simple example.
        // In reality, you could do fancy things like on the fly computations,
        // or database lookups.
    }
    throw new Exception('Unknown variable name: '.$varName);
}
?>
 

Then you can use the variableResolver like this:

<?php
$varRes = 'variableResolver';
$parser->setVariableResolver($varRes);
$parser->setExpression('3+ K');
echo $parser->getValue();
?>
 

User Defined Functions

You can register a user defined function to be used in the expression like this:

<?php
 include('mathparser/mathparser.php');

   $parser = new MathParser();
   $parser->createFunc('TIMESTWO', 'any_php_func_with_one_param', 1);
   $parser->setExpression('TIMESTWO(3)+1');
   echo $parser->getValue(); // prints 7
   
   // the implementation of your function is something like:
   function any_php_func_with_one_param($p) {
     return $p * 2;
   } 
?>
 

User defined function with any number of parameters

Sometimes you don�t know how many parameters a function may take. Here is an example function that multiples all numbers given to it:

<?php
include('mathparser/mathparser.php');

   $parser = new MathParser();
   $parser->createFunc('MULTIPLY', 'multiply_func', -1); // -1 means any number of params
   $parser->setExpression('MULTIPLY(2,3,4)+1');
   echo $parser->getValue(); // prints 25
   
   // the implementation of your function is something like:
   function multiply_func() {
     $p = func_get_args();
     $count = func_num_args();
     $tot=1;
     for($i=0; $i<$count; $i++){
          $tot*=$p[$i];
     }
     return $tot;
   } 
?>
 


Bestcode Math Parsers are also available on many platforms/languages such as:

Software License for your review.

Purchasing bcParserPHP - Math Parser for PHP

You can pay with credit card and download bcParserPHP immediately from our online store for only $29.95. It includes PHP source code and documentation. Upgrades are free for registered users. Licensing is per developer (or per web site owner). Site license option is available in the online store page. You can deploy the the component royalty free with your applications (websites) as many times as you want. Site license allows any number of developers use the component at your development site. Site License is $290.95. Site licenses can be purchased here.
Online Order Form

For technical questions please contact support@gobestcode.com

 

Following PHPUnit tests have been executed to test bcParserPHP code:

----------------------------------------------
STR(x) & "ABC"
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3ABC
Expected=3ABC
SUCCESS
----------------------------------------------
STR(x) + "ABC"
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3ABC
Expected=3ABC
SUCCESS
----------------------------------------------
SUBSTR("Hello", 1,3)+5
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=ell5
Expected=ell5
SUCCESS
----------------------------------------------
x + y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=7
Expected=7
SUCCESS
----------------------------------------------
x - y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=-1
Expected=-1
SUCCESS
----------------------------------------------
x *y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=12
Expected=12
SUCCESS
----------------------------------------------
x /2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1.5
Expected=1.5
SUCCESS
----------------------------------------------
x^2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=9
Expected=9
SUCCESS
----------------------------------------------
9%2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
 2.08
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=2.08
Expected=2.08
SUCCESS
----------------------------------------------
 2.08E-2 
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=0.0208
Expected=0.0208
SUCCESS
----------------------------------------------
 2.08E+2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=208
Expected=208
SUCCESS
----------------------------------------------
0*E-1*P
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable E = 1
Variable P = 2
Result=-2
Expected=-2
SUCCESS
----------------------------------------------
0*(E-1)*P
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable E = 1
Variable P = 2
Result=0
Expected=0
SUCCESS
----------------------------------------------
 0 * E - 1 * P
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable E = 1
Variable P = 2
Result=-2
Expected=-2
SUCCESS
----------------------------------------------
E-1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable E = 1
Result=0
Expected=0
SUCCESS
----------------------------------------------
(X*0)+2E-1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=0.2
Expected=0.2
SUCCESS
----------------------------------------------
(X*0)+2E+1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=20
Expected=20
SUCCESS
----------------------------------------------
100.00 + -10.00
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=90
Expected=90
SUCCESS
----------------------------------------------
((  (x)))-2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
x+sin(y)-sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x +sin(y)- sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x+ sin(y)-sin(  -(-y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x+sin (y)-sin(-1*-y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x+sin( y)-sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x+sin(y )-sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
x+sin( +y )-sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
 (x+sin( +y )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
( -x+sin( +y-1 )-sin(y-1) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=-3
Expected=-3
SUCCESS
----------------------------------------------
 (x+sin( +y )+max(x,7)-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max( x,7)-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max( x, (3+7)-3)-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max(7.0,x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max( 7.0 , x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max  ( 7.0 , x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=10
Expected=10
SUCCESS
----------------------------------------------
 (x+sin( +y )+max  ( 7.0E-8 , x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=6
Expected=6
SUCCESS
----------------------------------------------
 (x+sin( +y )+max  ( 7.0E+18 , x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=7.0E+18
Expected=7.0E+18
SUCCESS
----------------------------------------------
 (x+sin( +y )+max  ( 7.0E5 , x )-sin(y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=700003
Expected=700003
SUCCESS
----------------------------------------------
 -2+sum(x,y,5,7)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=17
Expected=17
SUCCESS
----------------------------------------------
 -2+sum(x,y,5, -7)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
 -2+sum(x,y,5 , -7)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
----------------------------------------------
 -2+sum(  x, +y,( 5+3) /2 , -7)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=2
Expected=2
SUCCESS
----------------------------------------------
if(x,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x-y,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x>y,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=0
Expected=0
SUCCESS
----------------------------------------------
if( x=x,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x=3.0 | x>9,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x=3.0|x>9,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x=3.0&xy), y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
if( x=3.0&!(x>y), y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=4
Expected=4
SUCCESS
----------------------------------------------
x=3
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
x=0
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=0
Expected=0
SUCCESS
----------------------------------------------
!x=0
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
x<>0
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
x<>3
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=0
Expected=0
SUCCESS
----------------------------------------------
x<>-y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
x+sin(pi)/y
3.23108510433E-15
1
2
3
4
5
6
7
8
9
SUCCESS
SUCCESS
SUCCESS
----------------------------------------------
x - sum( ) 
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=3
Expected=3
SUCCESS
Create variable A_1
----------------------------------------------
a_1*2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable A_1 = 1
Result=2
Expected=2
Remove variable A_1
----------------------------------------------
a_1*2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Sub expression "A_1" in "A_1*2" is not valid.
SUCCESS
Create variable E
----------------------------------------------
X-E-1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Variable E = 6
Result=-4
Expected=-4
Remove variable E
----------------------------------------------
X-E-1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Sub expression "E" in "X-E" is not valid.
SUCCESS
$this->parser->createFunc("F_1", F1, 1)
----------------------------------------------
f_1(x)+1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
Remove function F_1
----------------------------------------------
f_1(x)+1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Sub expression "F_1(X)" in "F_1(X)+1" is not valid.
SUCCESS
$this->parser->createFunc("F_2", F2, 2)
----------------------------------------------
f_2(x,y) + 1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=8
Expected=8
Remove function F_2
----------------------------------------------
f_2(x,y) + 1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Sub expression "F_2(X,Y) " in "F_2(X,Y) + 1" is not valid.
SUCCESS
$this->parser->createFunc("F_N", FN, -1)
----------------------------------------------
f_N(x,y,1,2,3) + 1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Parameter: 3  
Parameter: 4  
Parameter: 1  
Parameter: 2  
Parameter: 3  
Result=1
Expected=1
Remove function F_N
----------------------------------------------
f_N(x,y,1,2,3) + 1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Sub expression "F_N(X,Y,1,2,3) " in "F_N(X,Y,1,2,3) + 1" is not valid.
Invalid portion of expression: F_N(X,Y,1,2,3) 
0
SUCCESS
----------------------------------------------
3+ K 
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=8
Expected=8
----------------------------------------------
5+MA -6
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=199
Expected=199
----------------------------------------------
5+MA ()
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Expected: Sub expression "MA ()" in "5+MA ()" is not valid.
----------------------------------------------
IF(K>1,1,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Result=1
Expected=1
SUCCESS
----------------------------------------------
x + k
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " K" in "X + K" is not valid.
SUCCESS
----------------------------------------------
x - v
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " V" in "X - V" is not valid.
SUCCESS
----------------------------------------------
k *y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "K " in "K *Y" is not valid.
SUCCESS
----------------------------------------------
a /2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "A " in "A /2" is not valid.
SUCCESS
----------------------------------------------
 2.0.8
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.0.8" in " 2.0.8" is not valid.
SUCCESS
----------------------------------------------
 ..08E-2 
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "..08E" in "..08E-2" is not valid.
SUCCESS
----------------------------------------------
 2.08E+.2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E+.2" in " 2.08E+.2" is not valid.
SUCCESS
----------------------------------------------
 2.08E+2.
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E+2." in " 2.08E+2." is not valid.
SUCCESS
----------------------------------------------
 2.08E++2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E++2" in " 2.08E++2" is not valid.
SUCCESS
----------------------------------------------
 2.08E+-2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E+-2" in " 2.08E+-2" is not valid.
SUCCESS
----------------------------------------------
 2.08E--2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E--2" in " 2.08E--2" is not valid.
SUCCESS
----------------------------------------------
 2.08E.2
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " 2.08E.2" in " 2.08E.2" is not valid.
SUCCESS
----------------------------------------------
x+s in(y)-sin(y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "S IN(Y)" in "X+S IN(Y)" is not valid.
SUCCESS
----------------------------------------------
x +sin(y)- sin(co(3))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "CO(3)" in "SIN(CO(3))" is not valid.
SUCCESS
----------------------------------------------
x+ sin()-sin( -(-y) )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " SIN()" in "X+ SIN()" is not valid.
SUCCESS
----------------------------------------------
x(x+y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "X(X+Y)" in "X(X+Y)" is not valid.
SUCCESS
----------------------------------------------
2*(x-1
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "(X-1" in "2*(X-1" is not valid.
SUCCESS
----------------------------------------------
(x*(2+y)))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Bracket mismatch in expression "(X*(2+Y)))" at index 9.
SUCCESS
----------------------------------------------
(x*((2+y))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "(X*((2+Y))" in "(X*((2+Y))" is not valid.
SUCCESS
----------------------------------------------
()
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "()" in "()" is not valid.
SUCCESS
----------------------------------------------
1+)x+2)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Bracket mismatch in expression "1+)X+2)" at index 2.
SUCCESS
----------------------------------------------
 max( )
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Function MAX requires at least 1 parameters.
SUCCESS
----------------------------------------------
max( x,)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "X," in "MAX( X,)" is not valid.
SUCCESS
----------------------------------------------
 max (x-y,y))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Bracket mismatch in expression " MAX (X-Y,Y))" at index 12.
SUCCESS
----------------------------------------------
1-max(x,y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "MAX(X,Y" in "1-MAX(X,Y" is not valid.
SUCCESS
----------------------------------------------
ma x(sin(-x),cos(+y))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "MA X(SIN(-X),COS(+Y))" in "MA X(SIN(-X),COS(+Y))" is not valid.
SUCCESS
----------------------------------------------
max(2e4
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "MAX(2E4" in "MAX(2E4" is not valid.
SUCCESS
----------------------------------------------
max ( max(x,y) 
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "MAX(X,Y" in "MAX ( MAX(X,Y)" is not valid.
SUCCESS
----------------------------------------------
max(a,x)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "A" in "MAX(A,X)" is not valid.
SUCCESS
----------------------------------------------
1+max(sin2(x)+cos(pi))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "SIN2(X)" in "SIN2(X)+COS(PI)" is not valid.
SUCCESS
----------------------------------------------
1+max(x,b)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "B" in "MAX(X,B)" is not valid.
SUCCESS
----------------------------------------------
1+max(a,x)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "A" in "MAX(A,X)" is not valid.
SUCCESS
----------------------------------------------
sum(x,sin(a+b))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "A" in "A+B" is not valid.
SUCCESS
----------------------------------------------
sum(x,ff(x))
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "FF(X)" in "SUM(X,FF(X))" is not valid.
SUCCESS
----------------------------------------------
sum( 2+(k/2)+y-x)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "K" in "K/2" is not valid.
SUCCESS
----------------------------------------------
if(x?y:0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "IF(X?Y:0)" in "IF(X?Y:0)" is not valid.
SUCCESS
----------------------------------------------
if( x-y>0 then y else 0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "IF( X-Y>0 THEN Y ELSE 0)" in "IF( X-Y>0 THEN Y ELSE 0)" is not valid.
SUCCESS
----------------------------------------------
if( x>y,y)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "IF( X>Y,Y)" in "IF( X>Y,Y)" is not valid.
SUCCESS
----------------------------------------------
if( x =x,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " =X" in "X> =X" is not valid.
SUCCESS
----------------------------------------------
if( false ,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " FALSE " in "IF( FALSE ,Y,0)" is not valid.
SUCCESS
----------------------------------------------
if(true,y,0)
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "TRUE" in "IF(TRUE,Y,0)" is not valid.
SUCCESS
----------------------------------------------
if( x=3.0 and x0
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression " >0" in "X< >0" is not valid.
SUCCESS
----------------------------------------------
x<<>0
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "<>0" in "X<<>0" is not valid.
SUCCESS
----------------------------------------------
x<>=3
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "=3" in "X<>=3" is not valid.
SUCCESS
----------------------------------------------
x<=>-y
Variable PI = 3.14159265359
Variable X = 3
Variable Y = 4
Error: Sub expression "X<=>-Y" in "X<=>-Y" is not valid.
SUCCESS
Variable A does not exist.
SUCCESS
Create variable 1A_1
1a_1 is not a valid variable name.
SUCCESS
$this->parser->createFunc("F_1", F1, 1)
1F_1 is not a valid function name.
SUCCESS
$this->parser->createFunc("sin", F2, 2)
Function sin already exists.
SUCCESS


TestCase MathParserTest->testString1() passed
TestCase MathParserTest->testString2() passed
TestCase MathParserTest->testStringSubstr() passed
TestCase MathParserTest->testPlus() passed
TestCase MathParserTest->testMinus() passed
TestCase MathParserTest->testMult() passed
TestCase MathParserTest->testDiv() passed
TestCase MathParserTest->testPow() passed
TestCase MathParserTest->testModOper() passed
TestCase MathParserTest->testDoubleConst1() passed
TestCase MathParserTest->testDoubleConst2() passed
TestCase MathParserTest->testDoubleConst3() passed
TestCase MathParserTest->testScientific1() passed
TestCase MathParserTest->testScientific2() passed
TestCase MathParserTest->testScientific3() passed
TestCase MathParserTest->testScientific4() passed
TestCase MathParserTest->testScientific5() passed
TestCase MathParserTest->testScientific6() passed
TestCase MathParserTest->testSpace() passed
TestCase MathParserTest->testSpaceParanthesis() passed
TestCase MathParserTest->testSimple1() passed
TestCase MathParserTest->testSimple2() passed
TestCase MathParserTest->testSimple3() passed
TestCase MathParserTest->testSimple4() passed
TestCase MathParserTest->testSimple5() passed
TestCase MathParserTest->testSimple6() passed
TestCase MathParserTest->testSimple7() passed
TestCase MathParserTest->testSimple8() passed
TestCase MathParserTest->testSimple9() passed
TestCase MathParserTest->testTwoParam1() passed
TestCase MathParserTest->testTwoParam2() passed
TestCase MathParserTest->testTwoParam3() passed
TestCase MathParserTest->testTwoParam4() passed
TestCase MathParserTest->testTwoParam5() passed
TestCase MathParserTest->testTwoParam6() passed
TestCase MathParserTest->testTwoParam7() passed
TestCase MathParserTest->testTwoParam8() passed
TestCase MathParserTest->testTwoParam9() passed
TestCase MathParserTest->testNParam1() passed
TestCase MathParserTest->testNParam2() passed
TestCase MathParserTest->testNParam3() passed
TestCase MathParserTest->testNParam4() passed
TestCase MathParserTest->testIF1() passed
TestCase MathParserTest->testIF2() passed
TestCase MathParserTest->testGT() passed
TestCase MathParserTest->testLT() passed
TestCase MathParserTest->testLTEq() passed
TestCase MathParserTest->testGTEq() passed
TestCase MathParserTest->testEqOrGt() passed
TestCase MathParserTest->testEqOrGt2() passed
TestCase MathParserTest->testEqAndLt() passed
TestCase MathParserTest->testEqAndLt2() passed
TestCase MathParserTest->testEqAndNotLt() passed
TestCase MathParserTest->testEqAndNotLt2() passed
TestCase MathParserTest->testEq() passed
TestCase MathParserTest->testEq2() passed
TestCase MathParserTest->testNotEq3() passed
TestCase MathParserTest->testNotEq4() passed
TestCase MathParserTest->testNotEq5() passed
TestCase MathParserTest->testNotEq6() passed
TestCase MathParserTest->testOptimize() passed
TestCase MathParserTest->testgetX() passed
TestCase MathParserTest->testgetY() passed
TestCase MathParserTest->testNoParams() passed
TestCase MathParserTest->testCreateVar() passed
TestCase MathParserTest->testCreateVarE() passed
TestCase MathParserTest->testCreateFunc1() passed
TestCase MathParserTest->testCreateFunc2() passed
TestCase MathParserTest->testCreateFuncN() passed
TestCase MathParserTest->testVariableResolver() passed
TestCase MathParserTest->testNegPlus() passed
TestCase MathParserTest->testNegMinus() passed
TestCase MathParserTest->testNegMult() passed
TestCase MathParserTest->testNegDiv() passed
TestCase MathParserTest->testNegDoubleConst1() passed
TestCase MathParserTest->testNegDoubleConst2() passed
TestCase MathParserTest->testNegDoubleConst3() passed
TestCase MathParserTest->testNegDoubleConst4() passed
TestCase MathParserTest->testNegDoubleConst5() passed
TestCase MathParserTest->testNegDoubleConst6() passed
TestCase MathParserTest->testNegDoubleConst7() passed
TestCase MathParserTest->testNegDoubleConst8() passed
TestCase MathParserTest->testNegSimple1() passed
TestCase MathParserTest->testNegSimple2() passed
TestCase MathParserTest->testNegSimple3() passed
TestCase MathParserTest->testNegSimple4() passed
TestCase MathParserTest->testNegSimple5() passed
TestCase MathParserTest->testNegSimple6() passed
TestCase MathParserTest->testNegSimple7() passed
TestCase MathParserTest->testNegSimple8() passed
TestCase MathParserTest->testNegSimple9() passed
TestCase MathParserTest->testNegTwoParam1() passed
TestCase MathParserTest->testNegTwoParam2() passed
TestCase MathParserTest->testNegTwoParam3() passed
TestCase MathParserTest->testNegTwoParam4() passed
TestCase MathParserTest->testNegTwoParam5() passed
TestCase MathParserTest->testNegTwoParam6() passed
TestCase MathParserTest->testNegTwoParam7() passed
TestCase MathParserTest->testNegTwoParam8() passed
TestCase MathParserTest->testNegTwoParam9() passed
TestCase MathParserTest->testNegTwoParam10() passed
TestCase MathParserTest->testNegTwoParam11() passed
TestCase MathParserTest->testNegNParam1() passed
TestCase MathParserTest->testNegNParam2() passed
TestCase MathParserTest->testNegNParam4() passed
TestCase MathParserTest->testNegIF1() passed
TestCase MathParserTest->testNegIF2() passed
TestCase MathParserTest->testNegGT() passed
TestCase MathParserTest->testNegLT() passed
TestCase MathParserTest->testNegLTEq() passed
TestCase MathParserTest->testNegGTEq() passed
TestCase MathParserTest->testNegIffalse() passed
TestCase MathParserTest->testNegIftrue() passed
TestCase MathParserTest->testNegEqAndLt() passed
TestCase MathParserTest->testNegEqOrLt2() passed
TestCase MathParserTest->testNegEqAndNotLt() passed
TestCase MathParserTest->testNegEqAndNotGt2() passed
TestCase MathParserTest->testNegEq() passed
TestCase MathParserTest->testNegEq2() passed
TestCase MathParserTest->testNegNotEq3() passed
TestCase MathParserTest->testNegNotEq4() passed
TestCase MathParserTest->testNegNotEq5() passed
TestCase MathParserTest->testNegNotEq6() passed
TestCase MathParserTest->testNeggetVar() passed
TestCase MathParserTest->testNegCreateVar() passed
TestCase MathParserTest->testNegCreateFunc1() passed
TestCase MathParserTest->testNegCreateFunc2() passed
 

Software License for your review.

Purchasing bcParserPHP - Math Parser for PHP

You can pay with credit card and download bcParserPHP immediately from our online store for only $29.95. It includes PHP source code and documentation. Upgrades are free for registered users. Licensing is per developer (or per web site owner). Site license option is available in the online store page. You can deploy the the component royalty free with your applications (websites) as many times as you want. Site license allows any number of developers use the component at your development site. Site License is $290.95. Site licenses can be purchased here.
Online Order Form

For technical questions please contact support@gobestcode.com

 

Math Parser Online Store

webmaster@gobestcode.com