How to load javascript contents using php?

Go To StackoverFlow.com

1

How to load javascript contents using php. Suppose when php saves a file using, file get contents and file put contents, JavaScript contents like Google current ads is never loaded but the google adsense codes are loaded.

Can php "run" the JavaScript code on a saved page in order to save the dynamic content that the code generates? Already got the answer is NO. Is there any way or no Way?

2012-04-05 14:49
by NoName
I'm sorry, you'll have to clarify what you're looking for - Alex Turpin 2012-04-05 14:50
PHP cannot by itself execute javascript. You can parse HTML to extract <script> tags and fetch any remote scripts specified in the src= attribute, but again... PHP won't execute the JS code - Marc B 2012-04-05 14:52
Whats the question again - Baba 2012-04-05 14:52
Similar: http://stackoverflow.com/questions/1045845/how-to-call-a-javascript-function-from-ph - Chris Laplante 2012-04-05 14:54


1

You are asking whether or not PHP can "run" the JavaScript code on a saved page in order to save the dynamic content that the code generates. The answer is no, it cannot. Or at least, not without building your own JavaScript interpreter.

2012-04-05 14:52
by Chris Laplante
For what it's worth, there is http://us.php.net/manual/en/class.v8js.php .. - DCoder 2012-04-05 15:02
That's pretty cool. Recent feature - Chris Laplante 2012-04-05 15:03
Yes. You got my point. As php can't do the job, is there any way out there? Any other language or extension - NoName 2012-04-05 15:07
Not a specific language, no. But you might be able to use a GUI-less (headless) browser to render the page: http://htmlunit.sourceforge.net/ and then capture the resulting marku - Chris Laplante 2012-04-05 15:09
@SimpleCoder: it recently got covered in proggit and HN, but looking at it more closely it seems to be older than that: http://pecl.php.net/package/v8j - DCoder 2012-04-05 15:09
@SimpleCoder Hope you won't mind if i ask, Why JavaScript shows such a behavior. To increase Security or ... - NoName 2012-04-05 15:18
That's just how it works. The browser executes JavaScript - Chris Laplante 2012-04-05 15:20
Ads