RE: Getting source from remote file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On 6 May 2010 10:55, Peter Lind <peter.e.lind@xxxxxxxxx> 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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux