我收到此错误,但我无法找出原因:
Parse error: syntax error, unexpected $end in C:\wamp\www\test.php(19) : eval()'d code on line 1
任何见解将不胜感激!
$table = '<table><tr><td>${Q*10}</td></tr></table>';
$symbols = array('Q' => 10);
preg_replace_callback('/\${(\w+)([*+-\/])(\d+)}/', function($matches) use ($symbols, $table) {
return repl($matches, $symbols, $table);
}, $table);
function repl($tokens, $symbols, $table)
{
$replace = array_shift($tokens);
$operand1 = $symbols[$tokens[0]];
$operator = $tokens[1];
$operand2 = $tokens[2];
$val = eval("$operand1 $operator $operand2");
// Fix: $val = eval("return $operand1 $operator $operand2;");
$table = str_replace($replace, $val, $table);
echo $table; // Should be 100
}
// EOF