<?php
$input = '-16-1=';
$result = 'Нет ответа';
$regexp = '!([0-9\\.]+)!';
$example = preg_split($regexp, $input, 0, PREG_SPLIT_NO_EMPTY
| PREG_SPLIT_DELIM_CAPTURE);
$result = (float)$example[0];
foreach ($example as $key => $value)
if ($key % 2 === 1) {
switch($value) {
case '+': $result += (float)$example[$key+1]; break;
case '-': $result -= (float)$example[$key+1]; break;
case '*': $result *= (float)$example[$key+1]; break;
case '/': $result /= (float)$example[$key+1]; break;
case '=': echo "Ответ: ", $input, $result; break 2;
default: echo "Что-то пошло не так. Символы то верные ввёл?";
};
}
PD9waHAKCiRpbnB1dCA9ICctMTYtMT0nOwokcmVzdWx0ID0gJ9Cd0LXRgiDQvtGC0LLQtdGC0LAnOwokcmVnZXhwID0gJyEoWzAtOVxcLl0rKSEnOwoKJGV4YW1wbGUgPSBhcnJheSgpOwokZXhhbXBsZSA9IHByZWdfc3BsaXQoJHJlZ2V4cCwgJGlucHV0LCAwLCBQUkVHX1NQTElUX05PX0VNUFRZfAogCSAgICAgICBQUkVHX1NQTElUX0RFTElNX0NBUFRVUkUpOwogCSAgICAgICAKJHJlc3VsdCA9IChmbG9hdCkkZXhhbXBsZVswXTsKCmZvcmVhY2ggKCRleGFtcGxlIGFzICRrZXkgPT4gJHZhbHVlKQoJaWYgKCRrZXkgJSAyID09PSAxKSB7CgkJc3dpdGNoKCR2YWx1ZSkgewoJCQljYXNlICcrJzogJHJlc3VsdCArPSAoZmxvYXQpJGV4YW1wbGVbJGtleSsxXTsgYnJlYWs7CgkJCWNhc2UgJy0nOiAkcmVzdWx0IC09IChmbG9hdCkkZXhhbXBsZVska2V5KzFdOyBicmVhazsKCQkJY2FzZSAnKic6ICRyZXN1bHQgKj0gKGZsb2F0KSRleGFtcGxlWyRrZXkrMV07IGJyZWFrOwoJCQljYXNlICcvJzogJHJlc3VsdCAvPSAoZmxvYXQpJGV4YW1wbGVbJGtleSsxXTsgYnJlYWs7CgkJCWNhc2UgJz0nOiBlY2hvICLQntGC0LLQtdGCOiAiLCAkaW5wdXQsICRyZXN1bHQ7IGJyZWFrIDI7CgkJCWRlZmF1bHQ6IGVjaG8gItCn0YLQvi3RgtC+INC/0L7RiNC70L4g0L3QtSDRgtCw0LouINCh0LjQvNCy0L7Qu9GLINGC0L4g0LLQtdGA0L3Ri9C1INCy0LLRkdC7PyI7CgkJfTsKCX0=