Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = "222+bbbc24"; //przykładowe dane wejściowe
- $checkedStr="";
- $strLen = strlen($input);
- $checkedStrPointer=0;
- for($i=0;$i<$strLen;$i++)
- {
- 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')
- {
- $checkedStr[$checkedStrPointer] = $input[$i];
- $checkedStrPointer++;
- }
- }
- $result = eval('return '.$checkedStr.';'); //obliczenia matematyczne na sformatowanym ciągu znaków
- echo "$checkedStr.<br>"; //sformatowane działanie
- echo $result; //wynik dziłania
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement