You are here: Re: Extracting body from HTML document? « PHP Programming Language « IT news, forums, messages
Re: Extracting body from HTML document?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация