daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PHP: I have a string that has a mathematical operation in it. How do I run it?
  2. function testMath($char){
  3.     $array['math'] = Array("+", "-", "/", "*", "(", ")", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
  4.     foreach($char as $chr){
  5.         if(!in_array($chr, $array['math'){
  6.             return false;
  7.         }
  8.     }
  9.     return true;
  10. }
  11.    
  12. Parse error: parse error in C:UsersJoshDesktopApphtmlnew.php(24) : eval()'d code on line 1
  13.    
  14. function testMath($char){
  15.     if(strlen($char) > 10) return false;
  16.     $array['math'] = Array("+", "-", "/", "*", "(", ")", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
  17.     foreach($char as $chr){
  18.         if(!in_array($chr, $array['math'){
  19.             return false;
  20.         }
  21.     }
  22.     return true;
  23. }
  24.  
  25. $math = $_GET['do'];
  26. if(testMath($math)) eval("$result = " . $math . ";");
  27.  
  28. echo $math, ' = ', $result;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top