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?

3
  • 1
    I'm sorry, you'll have to clarify what you're looking for. Commented Apr 5, 2012 at 14:50
  • 1
    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. Commented Apr 5, 2012 at 14:52
  • Similar: stackoverflow.com/questions/1045845/… Commented Apr 5, 2012 at 14:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes. You got my point. As php can't do the job, is there any way out there? Any other language or extension.
Not a specific language, no. But you might be able to use a GUI-less (headless) browser to render the page: htmlunit.sourceforge.net and then capture the resulting markup
@SimpleCoder: it recently got covered in proggit and HN, but looking at it more closely it seems to be older than that: pecl.php.net/package/v8js
@SimpleCoder Hope you won't mind if i ask, Why JavaScript shows such a behavior. To increase Security or ...?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.