Reputation: 75
I want to get the result of shown JavaScript and HTML code. For example, when we write document.write("Hello")
, return "Hello"
.
Look at this code:
$html_code = <<<EOL
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<script>
document.write("Hello World");
</script>
</body>
</html>
EOL;
$result = getResult($html_code);
echo $result;
I want to get this result:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
Hello World
</body>
</html>
Upvotes: 1
Views: 304
Reputation: 1680
I understand that you want to get the result of a HTML page with embedded Javascript code on the server side, in the same script that generates this HTML and Javascript code.
You can not!
In brief: you expect a result on the server side which had to be produced on the client side before.
In your example you could directly have the PHP script generate the "Hello world" text - no need for Javascript.
Upvotes: 1