Re: capture a webpage to later process it
| From: | Alejandro Tesone | Date: | Tue, 02 May 2006 01:56:52 +0000 |
| Subject: | Re: capture a webpage to later process it | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41796@lists.php.net to get a copy of this message | ||
Maybe you are looking is CURL function.
On 4/29/06, John Hicks <johnlist@gulfbridge.net> wrote:
John Hicks wrote: J. Alejandro Ceballos Z. -JOAL- wrote:(eregi("result:([:alnum:]+).*([:alnum:]+\.jpg)",$result_webpage,$array_match))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'); ifIf 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 Here's a more useful use of the same idea: <?php if (isset($Url)) {{ echo "<h2>External status:".$array_match[1]."<br>image: <img src=\""..$array_match[2]."\"></h2>"; } ?> .... blah, blah, blah$ThePageContents = file_get_contents($Url); $TheNewPageContents = preg_replace( '/(<head[^>]*>)/', "\1<base href='$Url/' />", $ThePageContents); echo $TheNewPageContents;} else {echo "Enter a URL as a query string in this URL, e.g.: <br /><a href=\"${_SERVER['PHP_SELF']}?Url=http://www.yahoo.com\"http://${_SERVER['SERVER_NAME']}${_SERVER['PHP_SELF']}?Url=http://www.yahoo.com</a>"; } ?> This allows you to run your own rather sloppy proxy. Just plug the url you want into the query string for your page (or, better still, make a form to post it): https://mydomain.com/mypage.php?Url=http://DomainIWantToView.com/PageIWantToView.html The regex adds a <base> tag to the remote web page to make the images and links work. But of course, that means the gets of all the images, css, js, etc. will all show up with your workstation IP on the remote server's log (and on your boss's log of your browsing), so you haven't really accomplished much :( But it's kind of fun, huh? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php