I had been looking to store a web page content in a string variable using PHP for long time. I Googled, Yahooed a lot but was not successful! Finally I got an a clue!
You can use the PHP inbuilt function
ile_get_contents($url);
where $url contains the address of the web page you want to store! for example : $url = “http://www.bloggeradda.com/”;
But many web hosts may not allow file access method for their URLs! But you need not loose heart, there is a work around using CURL!
Here is the function for that:
function get_url_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
Note : It will only display web page output, not scripts.
Topic : Day-to-Day Tips









Leave a comment