<?php
$input = '/58.584+87/-4-882*-18=';
$regexp = '/((\\/|\\*|\\+|\\-)(\\/|\\*|\\+))|(^(\\/|\\*|\\+))/';
echo "Выражение введено с ошибкой";
}
$regexp = '/(?<=\\d)(\\+|\\*|\\/|\\-)(?=(\\-)?\\d(\\.)?)/';
$numbersAndSteps[0] = preg_split($regexp, $input, 0, PREG_SPLIT_NO_EMPTY
); foreach($numbeAndSteps[0] as $number) {
}
$regexp = '/((?<=\\+|\\*|\\/|\\-)\\-?\\d+\\.?\\d*)|(^\\-\\d+\\.?\\d*)/';
$numbersAndSteps[1] = preg_split($regexp, $input, 0, PREG_SPLIT_NO_EMPTY
);
$amountOfNumbers = count($numbersAndSteps[0]);
$sum = $numbersAndSteps[0][0];
for ($i = 0; $i < $amountOfNumbers ; $i++) {
$followingNumber = $numbersAndSteps[0][$i+1];
if($numbersAndSteps[1][$i] == '+'){
$sum = $sum + $followingNumber;
} elseif ($numbersAndSteps[1][$i] == '-'){
$sum = $sum - $followingNumber;
} elseif($numbersAndSteps[1][$i] == '*'){
$sum = $sum * $followingNumber;
} elseif ($numbersAndSteps[1][$i] == '/'){
$sum = $sum / $followingNumber;
}
}
echo "Ответ: {$sum}";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRpbnB1dCA9ICcvNTguNTg0Kzg3Ly00LTg4MiotMTg9JzsKCiRyZWdleHAgPSAnLygoXFwvfFxcKnxcXCt8XFwtKShcXC98XFwqfFxcKykpfCheKFxcL3xcXCp8XFwrKSkvJzsKaWYgKHByZWdfbWF0Y2goJHJlZ2V4cCwgJGlucHV0KSkgewoJZWNobyAi0JLRi9GA0LDQttC10L3QuNC1INCy0LLQtdC00LXQvdC+INGBINC+0YjQuNCx0LrQvtC5IjsKCWV4aXQ7Cn0KCiRyZWdleHAgPSAnLyg/PD1cXGQpKFxcK3xcXCp8XFwvfFxcLSkoPz0oXFwtKT9cXGQoXF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