Re: Manipulate web content

From: Date: Wed, 04 Aug 2004 00:08:16 +0000
Subject: Re: Manipulate web content
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-192638@lists.php.net to get a copy of this message
On Tue, 3 Aug 2004 20:00:56 -0400, Richard Bewley <rbewley@eq-sys.com> wrote: > Hi, > I am trying to do some work that involves parsing through the HTML of > some webpages. But, I cannot find an easy way in PHP to actually get that > HTML. Say, for example, I need the HTML returned from > http://www.yahoo.com/, I tried doing an fopen(), but the only > way I can do > it is if I use passthru, or exec and use the linux wget, then use fopen() on > that file. Does anyone know if there's an easy function or way of doing it? > I essentially need to download the web file, and store the contents of it in > a variable to manipulate with my program. > There are many ways to do this. The simplest is with the file functions, such as fopen and file_get_contents: $html = file_get_contents('http://www.yahoo,com'); These will only work if you have the fopen wrappers turned on in your php.ini. If this won't work for you, I would suggest using PEAR's HTTP_Request. http://pear.php.net/package/HTTP_Request It's a package that implements all of that in PHP code with sockets. It's also got lots of useful features. FYI, the HTTP_Client package is based on HTTP_Request and can take care of cookies and such for you so that it looks like a user ir browsing a site. :-) If you are new to PEAR, please go to this page to learn about it and how to install: http://pear.php.net/manual/en/introduction.php http://pear.php.net/manual/en/installation.php -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#192638) next »