Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $input = "222+bbbc24"; //przykładowe dane wejściowe
  4. $checkedStr="";
  5. $strLen = strlen($input);
  6. $checkedStrPointer=0;
  7. for($i=0;$i<$strLen;$i++)
  8. {
  9. if($input[$i]=='+' || $input[$i]=='-' || $input[$i]=='*' ||$input[$i]=='/' ||$input[$i]=='=' ||$input[$i]=='1' ||$input[$i]=='2' ||$input[$i]=='3' ||$input[$i]=='4' ||$input[$i]=='5' ||$input[$i]=='6' ||$input[$i]=='7' ||$input[$i]=='8' ||$input[$i]=='9')
  10. {
  11. $checkedStr[$checkedStrPointer] = $input[$i];
  12. $checkedStrPointer++;
  13. }
  14. }
  15.  
  16. $result = eval('return '.$checkedStr.';'); //obliczenia matematyczne na sformatowanym ciągu znaków
  17. echo "$checkedStr.<br>"; //sformatowane działanie
  18. echo $result; //wynik dziłania
  19.  
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement