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?

  • 1
    I'm sorry, you'll have to clarify what you're looking for. – Alex Turpin Apr 05 '12 at 14:50
  • 1
    PHP cannot by itself execute javascript. You can parse HTML to extract ` – Marc B Apr 05 '12 at 14:52
  • Similar: http://stackoverflow.com/questions/1045845/how-to-call-a-javascript-function-from-php – Chris Laplante Apr 05 '12 at 14:54

1 Answers1

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.

Chris Laplante
  • 29,338
  • 17
  • 103
  • 134
  • Yes. You got my point. As php can't do the job, is there any way out there? Any other language or extension. –  Apr 05 '12 at 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 markup – Chris Laplante Apr 05 '12 at 15:09
  • 1
    @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/v8js – DCoder Apr 05 '12 at 15:09
  • @SimpleCoder Hope you won't mind if i ask, Why JavaScript shows such a behavior. To increase Security or ...? –  Apr 05 '12 at 15:18