Re: capture a webpage to later process it

From: Date: Sat, 29 Apr 2006 02:46:48 +0000
Subject: Re: capture a webpage to later process it
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-41774@lists.php.net to get a copy of this message
J. Alejandro Ceballos Z. -JOAL- wrote:
I want to read the results of an URL address, to later process it and insert part of them as internal code. If I use include or require, they inserts ALL the resulting code, but I want to do something like: blah, blah, blah.... <?php $result_webpage = somephpfunc('http://other.sit/externalpage.html'); if (eregi("result:([:alnum:]+).*([:alnum:]+\.jpg)",$result_webpage,$array_match)) { echo "<h2>External status:".$array_match[1]."<br>image: <img src=\""..$array_match[2]."\"></h2>"; } ?> .... blah, blah, blah
If you have fopen wrappers enabled (see http://us2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen) then you can simply use file_get_contents() to read the web page into a string. You can then manipulate it with regexes like so: $Url = 'http://www.php.net'; $ThePageContents = file_get_contents($Url); $TheNewPageContents = preg_replace('/PHP/', 'Ruby :)', $ThePageContents); echo $TheNewPageContents; --J

« previous php.db (#41774) next »