Good day to all.
There is a line that the user enters into the input, from this input through php I consider this line. How can I make a message output if there is a division by zero in the line.
Thank you in advance for your response
Example:
"2 + 2/0" Message "division by zero"
"5/0 + 1" Message "division by zero"
|
1 answer
$arr = [ "2+2/0", "5/0+1" ]; foreach($arr as $val){ if(strpos($val, '/0') !== false) print "$val: Деление на ноль!\n"; } ?
- oneLord, why not just
strpos? - Alexey Shimansky - @ Alexey Shimansky, and spaces? - user207618
- @Other I have a calculator consisting of buttons, that is, a person enters numbers by pressing the buttons, so spaces are impossible) - tweeker
- @tweeker, Why then a string? Dynamically track someone who divides what and display an error when needed. - user207618
- @Other unfortunately, my skill is not so advanced. The only thing I’m up to, check the string) - tweeker
|