<?php

use PHPMathParser\Math;
require_once 'lib/PHPMathParser/Math.php';
$math = new Math();
$math->setDebug(true);
//Schaltet den Debug-Mode ein
$answer = $math->evaluate('(2 + 3) * 4');
echo " Das Ergebnis lautet: " . $answer;
// int(20)
$answer = $math->evaluate('1 + 2 * ((3 + 4) * 5 + 6)');
echo " Das Ergebnis lautet: " . $answer;
// int(83)
$answer = $math->evaluate('(1 + 2) * (3 + 4) * (5 + 6)');
echo " Das Ergebnis lautet: " . $answer;
// int(231)
$math->registerVariable('a', 4);
$answer = $math->evaluate('($a + 3) * 4');
echo " Das Ergebnis lautet: " . $answer;
// int(28)
$math->registerVariable('a', 5);
$answer = $math->evaluate('($a + $a) * 4');
echo " Das Ergebnis lautet: " . $answer;
// int(40)
$math->registerVariable('wert', 6);
$answer = $math->evaluate('-$wert^2');
echo " Das Ergebnis lautet: " . $answer;
$math->registerVariable('wert', 6);
$answer = $math->evaluate('-($wert^2)');
echo " Das Ergebnis lautet: " . $answer;
$math->registerVariable('wert', 6);
Beispiel #2
0
<?php

use PHPMathParser\Math;
require_once 'lib/PHPMathParser/Math.php';
$math = new Math();
$answer = $math->evaluate('(2 + 3) * 4');
var_dump($answer);
// int(20)
$answer = $math->evaluate('1 + 2 * ((3 + 4) * 5 + 6)');
var_dump($answer);
// int(83)
$answer = $math->evaluate('(1 + 2) * (3 + 4) * (5 + 6)');
var_dump($answer);
// int(231)
$math->registerVariable('a', 4);
$answer = $math->evaluate('($a + 3) * 4');
var_dump($answer);
// int(28)
$math->registerVariable('a', 5);
$answer = $math->evaluate('($a + $a) * 4');
var_dump($answer);
// int(40)
Beispiel #3
0
<?php

// Parse the expression and do the calculations.
$expression = $_POST['expression'];
use PHPMathParser\Math;
require_once '/var/www/html/lib/PHPMathParser/Math.php';
$math = new Math();
$result = $math->evaluate($expression);
//ob_start();
var_dump($result);
$result = ob_get_clean();
echo $result;
Beispiel #4
0
<?php

use PHPMathParser\Math;
require_once 'vendor/autoload.php';
$math = new Math();
//Positive Integer Tests
$answer = $math->evaluate('10 / 5');
var_dump($answer);
echo "<br /><br />";
// int(2)
$answer = $math->evaluate('(2 + 3) * 4');
var_dump($answer);
echo "<br /><br />";
// int(20)
$answer = $math->evaluate('1 + 2 * ((3 + 4) * 5 + 6)');
// 1 + 2 * (7 * 5 + 6)
// 1 + 2 * (35 + 6)
// 1 + 2 * 41
// 1 + 82
var_dump($answer);
echo "<br /><br />";
// int(83)
$answer = $math->evaluate('9 * (3+8) - 6 - 45');
var_dump($answer);
echo "<br /><br />";
// 99 - 6 - 45
// int(48)
$answer = $math->evaluate('1 * 2 + ((3 + 4) * 5 + 6)');
// 2 + (7 * 5 + 6)
// 2 + (35 + 6)
var_dump($answer);