Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP: I have a string that has a mathematical operation in it. How do I run it?
- function testMath($char){
- $array['math'] = Array("+", "-", "/", "*", "(", ")", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
- foreach($char as $chr){
- if(!in_array($chr, $array['math'){
- return false;
- }
- }
- return true;
- }
- Parse error: parse error in C:UsersJoshDesktopApphtmlnew.php(24) : eval()'d code on line 1
- function testMath($char){
- if(strlen($char) > 10) return false;
- $array['math'] = Array("+", "-", "/", "*", "(", ")", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
- foreach($char as $chr){
- if(!in_array($chr, $array['math'){
- return false;
- }
- }
- return true;
- }
- $math = $_GET['do'];
- if(testMath($math)) eval("$result = " . $math . ";");
- echo $math, ' = ', $result;
Add Comment
Please, Sign In to add comment