Are there any PHP libraries or tools available for safely evaluating mathematical terms inputted by users?

When evaluating mathematical terms inputted by users in PHP, it is important to ensure the safety and security of the evaluation process to prevent potential code injection attacks. One way to achieve this is by using libraries or tools that provide a safe environment for evaluating mathematical expressions. One popular library that can be used for this purpose is the `Symfony/ExpressionLanguage` component, which allows you to parse and evaluate mathematical expressions in a secure manner. By utilizing this library, you can safely evaluate user input without risking code execution vulnerabilities.

// Include the Symfony ExpressionLanguage component
require_once 'vendor/autoload.php';

// Create a new ExpressionLanguage instance
$expressionLanguage = new Symfony\Component\ExpressionLanguage\ExpressionLanguage();

// User input containing a mathematical expression
$userInput = "2 + 2";

// Evaluate the user input safely
$result = $expressionLanguage->evaluate($userInput);

// Output the result
echo $result;