How to Get and Display Content from Another Website using PHP

This code will grab the source code from whatever page you want and display it on YOUR OWN site. ┬áIn this case, we’re getting the source code from Yahoo!’s homepage. You can also replace the ‘echo $source’ part to save the contents into folder, etc. if you like.


$source = file_get_contents('http://yahoo.com');
//let's trim some of the code before we use it
//strip everything BEFORE the "opening" tag
$source = strstr($source, 'OPENING TAG');
//strip everything AFTER this. In this case, the "closing" tag
$source = str_replace(strstr($source, 'CLOSING TAG HERE'),'',$source);
echo $source;

 

Follow: