I would like to read a web page from another site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jalapenos
Forum Newbie
Posts: 3
Joined: Tue Mar 16, 2004 8:22 pm

I would like to read a web page from another site

Post by jalapenos »

Hi There

I would like to know if it's possible in PHP to read and take some part off the information inside a web site, like test.com/test.html and display only a part of the information to test2.com/test2.php ???

Or taking the code of a form from test.com/test.php and display the result or a part of the result to test2.com/test2/php ?



Thanks
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yes.
jalapenos
Forum Newbie
Posts: 3
Joined: Tue Mar 16, 2004 8:22 pm

Post by jalapenos »

Yes both of it or yes only the first one ?
alucard
Forum Newbie
Posts: 3
Joined: Wed Mar 17, 2004 5:49 am

Post by alucard »

Yes both :)
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: I would like to read a web page from another site

Post by TheBentinel.com »

jalapenos wrote:Hi There

I would like to know if it's possible in PHP to read and take some part off the information inside a web site, like test.com/test.html and display only a part of the information to test2.com/test2.php ???

Or taking the code of a form from test.com/test.php and display the result or a part of the result to test2.com/test2/php ?



Thanks
Look into file_get_contents($url) and the string functions. You'll need something like:

Code: Select all

$url = "http://cnn.com";
  $html = file_get_contents($url);
  print ($html);
That will let you mimic the CNN site, though images and scripts and other relative path related things may not work. If you wanted to grab a form from within that, you could do a strpos for "<form" and "</form" and grab everything inbetween.

Hope that helps!
jalapenos
Forum Newbie
Posts: 3
Joined: Tue Mar 16, 2004 8:22 pm

Post by jalapenos »

Thanks !!!
Last edited by jalapenos on Wed Mar 17, 2004 8:26 am, edited 1 time in total.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You may also want to explore the [php_man]CURL[/php_man] library (default library with PHP) - file_get_contents doesn't always work reliably.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

patrikG wrote:You may also want to explore the [php_man]CURL[/php_man] library (default library with PHP) - file_get_contents doesn't always work reliably.
Thanks for mentioning this. file_get_contents -- while temptingly easy to use -- does indeed fail too often for comfort. It seems that if it works, then it works. Like CNN, for example, always seems to work. But microsoft.com doesn't. Something to do with their redirect? I don't know.

Anyway, thanks for that!
Post Reply