What I have and want to do
-
I have an
input area. -
I have a JS script what reads the
input area‘sinnerHTMLand encodes it usingencodeURICompontentthen sends the value toevaluate.php?code=+value; -
I have an
evaluate.phpwhatGET‘s thecode‘s value from the URL and returns an evaluated value usingeval($code)to the javascript. -
And at the end it puts the
xmlHttp.responseTextto adiv.
But I get this error when the eval is executed:
Parse error: syntax error, unexpected ‘”‘, expecting T_STRING in /Applications/MAMP/htdocs/Apps/editor/includes/exe.php(5) : eval()’d code on line 1
Evaluate.php
if(isset($_GET["code"])){
$e = $_GET["code"];
echo eval($e);
}
The value what I try to evaluate is just:
echo "Hello World!";
Then this is looks like in $_GET["code"] as:
echo \"Hello World!\";
According to PHP’s documentation:
So I think there may be a problem when you run
echo eval($e).P.S. It’s best practice not to use double quotes in PHP unless a variable is contained within those quotes. For example, use
"Hello, $name"and use'Hello, Bob'.