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

[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