RE: [PHP] Getting source from remote file

From: Date: Thu, 06 May 2010 12:20:35 +0000
Subject: RE: [PHP] Getting source from remote file
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-304951@lists.php.net to get a copy of this message
> On 6 May 2010 10:55, Peter Lind <peter.e.lind@gmail.com> wrote: > > You could parse the document with the DOM classes. Load as a > DOMDocument, then grab what's needed with the relevant methods (you > can use xpath to single out your divs with the right classes). > http://dk2.php.net/domdocument > > > Xpath is indeed the way to go. For example... > > > /* .. your code.. */ > > $data = file_get_contents($url); > > $inDoc = new DOMDocument(); > $inDoc->preserveWhiteSpace = false; > @$inDoc->loadHTML($data); > > $xpath = new DOMXPath($inDoc); > $xlinks = $xpath->query('//div[@class="b"]/a'); > for ($a = 0, $z = $xlinks->length; $a < $z; ++$a) { > $link = $xlinks->item($a); > $href = $xlink->attributes->getNamedItem('href')->value; > > } > > To be safe, you should use an ID instead of a class, though. > > Michiel Hi all, and thanks a lot for your suggestions. It works well now. The only problem I do have are german "Umlaute" [äöü] when receiving the content of the remote page. It#s formatted in iso-8859-1 and I'd rather have it in UTF-8. But utf8_de/encode won't help me there, I'm afraid. Anyhow, thanks a lot for your help! Chris

« previous php.general (#304951) next »