<?php
$input = "1+2*3/2*4-6=";
$tester = '#[\d\+\-*/=\s]#';
echo "Формат неверен";
}
}
echo "Вычисляем значение выражения: $input\n";
$devider = '#(\+|-|\*|=|/)#';
$parts = preg_split($devider, $input,0, PREG_SPLIT_DELIM_CAPTURE
); $result = $parts[0];
for($i=1; $i<$length; $i++) {
if ($parts[$i] == "+") {
echo "$result + {$parts[$i+1]} = ";
$result += $parts[$i+1];
echo "$result\n";
} elseif ($parts[$i] == "-") {
echo "$result - {$parts[$i+1]} = ";
$result -= $parts[$i+1];
echo "$result\n";
} elseif ($parts[$i] == "*") {
echo "$result * {$parts[$i+1]} = ";
$result *= $parts[$i+1];
echo "$result\n";
} elseif ($parts[$i] == "/") {
echo "$result / {$parts[$i+1]} = ";
$result /= $parts[$i+1];
echo "$result\n";
}
}
echo "Ответ равен: $result";
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKJGlucHV0ID0gIjErMiozLzIqNC02PSI7CgokdGVzdGVyID0gJyNbXGRcK1wtKi89XHNdIyc7CmZvciAoJGk9MDsgJGk8bWJfc3RybGVuKCRpbnB1dCk7ICRpKyspIHsKCWlmICghcHJlZ19tYXRjaCgkdGVzdGVyLCBtYl9zdWJzdHIoJGlucHV0LCAkaSwgMSkpKSB7CgkJZWNobyAi0KTQvtGA0LzQsNGCINC90LXQstC10YDQtdC9IjsKCQlleGl0KCk7Cgl9IAp9CgplY2hvICLQktGL0YfQuNGB0LvRj9C10Lwg0LfQvdCw0YfQtdC90LjQtSDQstGL0YDQsNC20LXQvdC40Y86ICRpbnB1dFxuIjsKCiRkZXZpZGVyID0gJyMoXCt8LXxcKnw9fC8pIyc7CiRwYXJ0cyA9IHByZWdfc3BsaXQoJGRldmlkZXIsICRpbnB1dCwwLCBQUkVHX1NQTElUX0RFTElNX0NBUFRVUkUpOwokbGVuZ3RoID0gY291bnQoJHBhcnRzKTsKJHJlc3VsdCA9ICRwYXJ0c1swXTsKCmZvcigkaT0xOyAkaTwkbGVuZ3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