How can I load the content of a web page into a variable?
I need to store the HTML in a string.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Provided
allow_url_fopenis enabled, you can just usefile_get_contents:And, if you need more options, take a look at Stream Functions — there is an example on the
stream_context_createmanual page where a couple of HTTP-headers are set.If `allow_url_fopen` is disabled, another solution is to work with [**curl**][5] — means a couple more lines of code, though.
Something as basic as this should work in the simplest situations :
But note that you might need some additional options — see the manual page of
curl_setoptfor a complete list.For instance :
CURLOPT_FOLLOWLOCATION, so redirects are followed.