<?php
$input = '5+6*2+1=' ;
$number = 0 ;
$result = 0 ;
$op = ' ' ;
for ( $i = 0 ; $i < $inputLenght ; $i ++ ) {
if ( $char == '*' || $char == '+' || $char == '-' || $char == '=' ) {
switch ( $op ) {
case '+' :
case '*' :
case '-' :
case '=' :
}
echo "op = [$op ] , result = [$result ], number = [$number ], char = [$char ] \n " ;
$number = 0 ;
$op = $char ;
$number = ( $number * 10 ) + $char ;
} else {
echo " WRONG SYMBOL: {$char} \n " ;
}
}
echo " Ответ: $input $result " ;
PD9waHAKJGlucHV0ID0gJzUrNioyKzE9JzsKJGlucHV0TGVuZ2h0ID0gbWJfc3RybGVuKCRpbnB1dCk7CgokbnVtYmVyID0gMDsKJHJlc3VsdCA9IDA7CiRvcCA9ICcgJzsKCmZvcigkaSA9IDA7ICRpIDwgJGlucHV0TGVuZ2h0OyAkaSsrKXsKCSRjaGFyID0gbWJfc3Vic3RyKCRpbnB1dCwgJGksIDEpOwoJaWYoJGNoYXIgPT0gJyonIHx8ICRjaGFyID09ICcrJyB8fCAkY2hhciA9PSAnLScgfHwgJGNoYXIgPT0gJz0nKSB7CgogICAgc3dpdGNoKCRvcCl7CiAgICAJY2FzZSAnKyc6CiAgICAJCSRyZXN1bHQgPSBpbnR2YWwoIiRyZXN1bHQiKSArIGludHZhbCgiJG51bWJlciIpOwogICAgCWNhc2UgJyonOgogICAgCQkkcmVzdWx0ID0gaW50dmFsKCIkcmVzdWx0IikgKiBpbnR2YWwoIiRudW1iZXIiKTsKICAgIAljYXNlICctJzoKICAgIAkJJHJlc3VsdCA9IGludHZhbCgiJHJlc3VsdCIpIC0gaW50dmFsKCIkbnVtYmVyIik7CiAgICAJY2FzZSAnPSc6CiAgICAJCSRyZXN1bHQgPSBpbnR2YWwoIiRyZXN1bHQiKSArIGludHZhbCgiJG51bWJlciIpOwogICAgCQogICAgCQkKICAgIAkJCiAgICB9CiAgICBlY2hvICJvcCA9IFskb3BdICwgcmVzdWx0ID0gWyRyZXN1bHRdLCBudW1iZXIgPSBbJG51bWJlcl0sIGNoYXIgPSBbJGNoYXJdIFxuIjsKICAgICRudW1iZXIgPSAwOwoJJG9wID0gJGNoYXI7CgkKCQoJCgl9ZWxzZWlmIChpc19udW1lcmljKCRjaGFyKSkgewoJCQoJICAgICRudW1iZXIgPSAoJG51bWJlciAqIDEwKSArICRjaGFyOyAKCSAgICAKCQkKCX1lbHNlIHsKCSAgICBlY2hvICIgV1JPTkcgU1lNQk9MOiB7JGNoYXJ9IFxuIjsJCgl9Cn0KCgogICAgZWNobyAiINCe0YLQstC10YI6ICRpbnB1dCAkcmVzdWx0Ijs=
stdout
op = [ ] , result = [0], number = [5], char = [+]
op = [+] , result = [36], number = [6], char = [*]
op = [*] , result = [72], number = [2], char = [+]
op = [+] , result = [73], number = [1], char = [=]
Ответ: 5+6*2+1= 73