How to use file_get_contents on Ajax site

限于喜欢 提交于 2019-12-05 18:03:34

No. Using file_get_contents() will only return the page contents, it will not execute any JavaScript on the page itself. The analog of this behaviour is almost equivalent to "View Page Source" in a browser.

The snippet

$website = 'http://stackoverflow.com/';
file_gets_contents($website)

loads the result of the HTTP-request, nothing else. Thus, the call loads the source of the html-page returned by the URL http://stackoverflow.com/.

Especially, file_gets_contents() does not load stuff referenced by the page pointed to by http://stackoverflow.com/.

Evaluating JavaScript code using PHP

In case you'd like to evaluate JavaScript inside of HTML-code using a PHP-script, you'd probably wish to use the V8 JavaScript engine, which needs to be compiled into your PHP-binary:

Find an example how to use the V8 JavaScript engine here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!