Page 1 of 1

I would like to read a web page from another site

Posted: Tue Mar 16, 2004 8:22 pm
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

Posted: Tue Mar 16, 2004 10:59 pm
by m3mn0n
Yes.

Posted: Wed Mar 17, 2004 6:02 am
by jalapenos
Yes both of it or yes only the first one ?

Posted: Wed Mar 17, 2004 6:04 am
by alucard
Yes both :)

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

Posted: Wed Mar 17, 2004 8:23 am
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!

Posted: Wed Mar 17, 2004 8:25 am
by jalapenos
Thanks !!!

Posted: Wed Mar 17, 2004 8:25 am
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.

Posted: Wed Mar 17, 2004 8:34 am
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!