|
Posted by Rik Wasmus on 11/14/07 21:54
On Wed, 14 Nov 2007 22:23:54 +0100, Andre-John Mas =
<andrejohn.mas@gmail.com> wrote:
> Hi,
>
> I am wanting to be able to get a section of a HTML document, by
> specifying an XPath. For example:
>
> $title=3D GetSection ( '/html/head/title');
> $body=3D GetSection ( '/html/body');
>
> I made a simple parser myself some time back, but it is failing with
> certain types of documents. Instead of maintaining the code, I would
> reather find an existing solution, so that I can concentrate my
> development efforts elswhere. Does anyone have anything they can
> recommend?
http://www.php.net/dom
<?php
$doc =3D new DOMDocument();
$doc->loadHTMLFile('test.html');
//just by tagname:
$title=3D $doc->getElementsByTagName('title')->item(0);
//or XPATH
$xpath =3D new DOMXPath($doc);
$tables =3D $xpath->query('//table');
?>
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|