Reputation: 505
When you use file_gets_contents($website)
or cURL to load a website, does it load the whole website? I am mostly interested about using cURL.
I am using it to load a webpage that then gets some contents such as price using AJAX and it has some problems getting the prices.
When I use file_get_contents, does it load as normally as a whole website does on a browser plus the stuff loaded using Ajax?
Upvotes: 4
Views: 8594
Reputation: 11999
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.
Upvotes: 0
Reputation: 1471
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.
Upvotes: 4