<?php
$input = '1=' ;
$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} " ;
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRpbnB1dCA9ICcxPSc7CgokcmVnZXhwID0gJy8oKFxcL3xcXCp8XFwrfFxcLSkoXFwvfFxcKnxcXCspKXwoXihcXC98XFwqfFxcKykpLyc7CmlmIChwcmVnX21hdGNoKCRyZWdleHAsICRpbnB1dCkpIHsKCWVjaG8gItCS0YvRgNCw0LbQtdC90LjQtSDQstCy0LXQtNC10L3QviDRgSDQvtGI0LjQsdC60L7QuSI7CglleG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