3v4l.org

run code in 300+ PHP versions simultaneously
<?php $_GET['msg']="what is 5 + 5 ?"; $msg=$_GET['msg']??"no msg!"; file_put_contents('msg.log.txt',$msg."\r\n",FILE_APPEND|LOCK_EX); $matches=NULL; $isMatch=preg_match("/(\d+)\s*(\+|\-|\*|\/|\:)\s*(\d+)/",$msg,$matches); if($isMatch){ $l=(int)$matches[1]; $o=$matches[2]; $r=(int)$matches[3]; switch($o){ case '+': $res=$l+$r; break; case '-': $res=$l-$r; break; case '*': $res=$l*$r; break; case '\\': case ':': $res=$l/$r; break; default: throw new \LogicException("invalid operator passed regex??!"); } echo "!check {$res}"; }

preferences:
51.1 ms | 402 KiB | 5 Q