Fetch Other Website Content Using PHP

Introduction:

Hello guys. Today I am going to introduce a PHP Programming code which will help you to grab other website content to your website without let your visitors know about the grabbing. I used the programming for creating Live Cricket Score Website and News Website. So let's get in to the tutorial.

About CURL in PHP Programming: 

The cURL library (or, 'libcurl' which is the package name on the server) is often used in PHP to access data from outside web pages. Common uses include reading rss feeds or accessing third-party API systems. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols.

How to Grab Other Website Content Using CURL in PHP?

It is very easy to grab other website content using CURL PHP. There is different method available to do this. Just follow the steps that given below.
$html=file_get_contents("http://www.somewebsite.com") 
  • The above code will help you to bring the whole website content to your web page. You can use the above code to display an offer page or something from other website. In order to display the content, You have to echo the $html variable.
$url = 'https://somedomain.com/somesite/';
$content = file_get_contents($url);
$first_step = explode( '<div id="thediv">' , $content );
$second_step = explode("</div>" , $first_step[1] );

echo $second_step[0];
  • The above code will helps you to pull other website content area wise. Example: You can pull just an area which display score board. Replace the <div id="thediv"> with the other website div class id which you want to display on your website.
There is lot's of other things which We can do with the CURL in PHP Programming. Example Applications like Search Engine Spider, CMS Updater, Etc are developing with the CURL. Work with the above code and give us your feedback.

Articles Related to Programming:

I hope you well enjoyed this article. If you have any doubts related to this article, Please let Me know by using the comment box that given below.Thanks

2 comments:

  1. file_get_contents function comes under Filesystem Functions category. And it is mainly used for file management of local system (or own file system of hosted server). for remote file management php curl is used ( i know it is a bit complicated, but it has more powerful and reliable options). you can check official php curl documentation here :PHP: cURL - Manual. And an example of parsing html contents using php curl is here : htmlparsing.com: Your guide to parsing HTML. Anyway thank you for your good work.

    ReplyDelete

Wapmaster or Webmaster can Comment Us with the following Comment Box . Don't add Links to your site for Spamming our Blog .. Once you add Comment with Link . It will be deleted immediatly by our Admins .

 
Top