Last active
August 29, 2015 14:02
-
-
Save d9k/239b54b9733c5dddbc04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Online PHP Script Execution</title> | |
</head> | |
<body> | |
<?php | |
function var_export54($var, $indent="") { | |
switch (gettype($var)) { | |
case "string": | |
return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; | |
case "array": | |
$indexed = array_keys($var) === range(0, count($var) - 1); | |
$r = []; | |
foreach ($var as $key => $value) { | |
$r[] = "$indent " | |
. ($indexed ? "" : var_export54($key) . " => ") | |
. var_export54($value, "$indent "); | |
} | |
return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; | |
case "boolean": | |
return $var ? "TRUE" : "FALSE"; | |
default: | |
return var_export($var, TRUE); | |
} | |
} | |
function parseAndPrint($codeSnippet){ | |
$codeSnippet = "<?php ".$codeSnippet."?>"; | |
echo "<b><pre>".htmlentities($codeSnippet)."</pre></b>"; | |
$namedTokens = []; | |
foreach (token_get_all($codeSnippet) as $token){ | |
if (is_array($token) && isset($token[0]) && is_numeric($token[0])){ | |
$token[0] = token_name($token[0]); | |
} | |
$namedTokens[] = $token; | |
}; | |
echo "<pre>".htmlentities(var_export54($namedTokens))."</pre>"; | |
} | |
//parseAndPrint("echo"); | |
//parseAndPrint("// comment"); | |
//parseAndPrint("function test(\$a){return \$a+1}"); | |
$code =<<<'BLOCK' | |
return CMap::mergeArray($config, array( | |
'db'=>[ | |
'connectionString' => '...string' | |
] | |
)); | |
BLOCK; | |
parseAndPrint($code); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment