What are the potential pitfalls of using preg_split in PHP for splitting mathematical terms?

Using preg_split to split mathematical terms can be problematic because it may not handle all possible mathematical expressions correctly, especially if they contain complex operators or parentheses. To solve this issue, it is recommended to use a dedicated mathematical expression parser library in PHP, such as the evalMath library, which can safely evaluate and parse mathematical expressions.

// Example of using the evalMath library to parse mathematical expressions
require_once 'evalmath.class.php';

$evalMath = new EvalMath();
$expression = "3 + 4 * (2 - 1)";
$result = $evalMath->evaluate($expression);

echo $result; // Output: 7