Execute javascript in PHP

Posted by Andreas Bonini on Stack Overflow See other posts from Stack Overflow or by Andreas Bonini
Published on 2010-04-23T14:08:30Z Indexed on 2010/04/23 14:13 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I'm generating your typical Web 2.0 HTML page with PHP: it contains a lot of <script> tags and javascript code that will substantially change the DOM after the load event.

Is there a way to get the final HTML code directly from PHP, without opening the page with any browser?

For example, let's say the HTML for the page is (it's just an example):

<html>
<head>
<script>...the jquery library code...</script>
<script>$(document).ready(function() { $("body").append("<p>Hi!</p>");</script>
</head>
<body>
</body>
</html>

This HTML is saved in the $html PHP variable. Now, I want to pass that variable to some function that will return $result = <html>....<body><p>Hi!</p></body></html>.

Is this possible?

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript