<?php
$input='243 + 6743 - 78 * 2 =';
echo "At first I was like $input...\n";
preg_match('/^[1-9]*/',$input,$match);
$sum=$match[0];
$operand1=$match[0];
$substrLength=strspn($input,"1234567890",(strlen($sum)+1));
calculateIt($input,$operand1,(substr($input,strlen($sum)+1,$substrLength)),$sum);

function calculateIt($input,$operand1,$operand2,$sum)
{

$substrLength=strspn($input,"1234567890",(strlen($sum)+1));
$operand2=substr($input,strlen($sum)+1,$substrLength);
$oper=substr($input,(strlen($sum)),1);
switch ($oper)
{
    case "+": $sum+=$operand2; break;
    case "-": $sum-=$operand2; break;
    case "*": $sum*=$operand2; break;
    case "/": $sum/=$operand2; break;
}
$input=str_replace($operand1.$oper.$operand2,$sum,$input);
echo "...and then I    $input \n";
$operand1=$sum;
if (substr($input,strlen($sum),1)!='=')
calculateIt($input,$operand1,$operand2,$sum);
else echo "Finally I became this... $sum";
}