how to get the contents of another file with php

There are many times when you may need to get the contents of another file on a server with php. Rather it is XML, html, or an RSS feed this is how to do it. The best way of doing this is to use this:

function fetch_content($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;

}

You should now have the content of the $url stored in a string calue. Note that this will not fetch any supporting files such as CSS of javascript. You will have to further parse these files to store their contents into a seperate string value.

Follow

Get every new post delivered to your Inbox.