This is a discussion on Downloading and parsing web-stuff within the PHP Language forums, part of the PHP Programming Forums category; Very basic: What is the easiest way in php to download the source code (HTML etc.) of a given URL (...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Very basic:
What is the easiest way in php to download the source code (HTML etc.) of a given URL (say, http://www.google.com) and parse this code for certain patterns? I guess my question can be split in two: 1) How do I download a webpage (into a string or whatever)? 2) How can I do string manupulation, regexp matching, information extraction etc. on the downloaded information? /David |
|
|||
|
David Rasmussen wrote: > I guess my question can be split in two: > > 1) How do I download a webpage (into a string or whatever)? $string = file_get_contents('http://some.url/blah'); > 2) How can I do string manupulation, regexp matching, information > extraction etc. on the downloaded information? now look at the docs for preg_match or ereg I prefer preg_match if ( preg_match('|<title>(.*?)</title>|',$string,$matches) ) { print_r($matches); } |
|
|||
|
Treat a full URL as a file.
$contents = implode( file("http://www.google.com/", ''\n") ); Then go to www.php.net/preg_match/ to read up on PCRE (Perl compatible regular expressions). See also ereg_* functions. HTH. -Mike -- Melt away the Cellulite with Cellulean! http://www.MeltAwayCellulite.com/ "David Rasmussen" <david.rasmussen@gmx.net> wrote in message news:42683c71$0$158$edfadb0f@dtext02.news.tele.dk. .. > Very basic: > > What is the easiest way in php to download the source code (HTML etc.) > of a given URL (say, http://www.google.com) and parse this code for > certain patterns? > > I guess my question can be split in two: > > 1) How do I download a webpage (into a string or whatever)? > > 2) How can I do string manupulation, regexp matching, information > extraction etc. on the downloaded information? > > /David > |