How do I get the HTML code of a web page in PHP? -
I want to get the HTML code of a link (web page) in PHP. For example, if the link
Then I want the HTML code of the page which is served. I want to retrieve this HTML code and store it in PHP variables.
How can I do this?
The easiest way is if your PHP server allows url fopen wrappers:
$ html = file_get_contents ('http://stackoverflow.com/questions/ask'); If you need more control then you should see the functions:
$ c = curl_init ('http://stackoverflow.com/questions / ask'); Curl_setopt ($ c, CURLOPT_RETURNTRANSFER, true); // curl_setopt (... other options you want ...) $ html = curl_exec ($ c); If (curl_error ($ c)) die (curl_error ($ c)); // Get status code $ status = curl_getinfo ($ c, CURLINFO_HTTP_CODE); Curl_close ($ c);
Comments
Post a Comment