- var_dump: documentation ( source)
- preg_match: documentation ( source)
- register_shutdown_function: documentation ( source)
- getcwd: documentation ( source)
- json_encode: documentation ( source)
- file_put_contents: documentation ( source)
<?php
$msg=(string)($_GET['message']?? $_POST['message'] ?? "no message!");
$answer=NULL;
var_dump(getcwd());
register_shutdown_function(function()use(&$answer){
var_dump(getcwd());
file_put_contents(__DIR__.DIRECTORY_SEPARATOR.'msg.log.txt',json_encode(['answer'=>$answer,'$_GET'=>$_GET],JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS ),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??!");
}
$answer="!check {$res}";
echo $answer;
}