PHPBuilder - Retrieve content from other web site

RSS Twitter
Tips Tricks And Hacks

Retrieve content from other web site

by: mario
September 28, 2000

This article will give you a brief explanation about how to get the content from others web sites. Before we go on, I must to remind you that the content that you will retrieve is opened for the public. However I won't make any responsibility of any claim from the owner of the sites.

Sometimes we want give the public information to the user of our sites, oneway to do that was make sure your eyes keep opened from the 'public sites' and you must work quickly to update your site with the 'updated information'. Preety hard here to give you an example what is the 'public sites' I talking about. Let's said for example : Newspaper Headline, Market Stock, Cinema's Schedule or even our favorite sites -->

So.. for our example I will give you how to get the content from to inform our user about the latest version of PHP. I'm sure the will give us permission to make the example, since I'm not doing any commercial things here .. =)

Let's take a look of the example...

1.$url = '';

2.$lines_array = file($url);

3.$lines_string = implode('', $lines_array);

4.eregi("<!-->(.*)<!-- end body -->", $lines_string, $head);

5.$lines = split("\n", $head[0]);

6.$x = count($lines);

7.for ($i=0;$i<$x;$i++) {
  echo $lines[$i];

The explanation :
1. Specified the url (or the page) that we will gonna retrieve 2. Store the whole code into array called $lines_array 3. We parse the content from $lines_array into $lines_string 4. We 'cut' the whole code with an eregi function.. in this case we want to take the information which is start from the <!--> until ended with <!-- end body -->. How do I know this ?? Check the HTML source from =) 5. Split them into new array.. in this case we split them with a newline character 6. and 7. We loop the whole array and write it into our HTML source.

That's all folks.. maybe the example is to simple, but not bad for an amateur like me.. =). Make any modification from the code, and u will have a fresh HTML page daily-updated... ;)


Comment and Contribute

Your comment has been submitted and is pending approval.




(Maximum characters: 1200). You have characters left.