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

Posted by Andre-John Mas on 11/15/07 15:47

Thanks for the help :)

On Nov 14, 11:26 pm, jebblue <n...@n.nnn> wrote:
> On Wed, 14 Nov 2007 14:46:43 -0800, Andre-John Mas wrote:
>
> > Thanks for the answer, though I am not sure how go from here to having a
> > sub-section of the HTML text. Basically what I am wanting to do is
> > extract the body section of an HTML document, to be able to insert it
> > into another.
>
> > Andre
>
> <?php
> $doc = new DOMDocument();
> $doc->loadHTMLFile('http://www.some_site_goes_here_or_some_file.nnn');
>
> //just by tagname:
> $body = $doc->getElementsByTagName('body')->item(0);
> print nodeDump($body);
>
> //or XPATH
> //$xpath = new DOMXPath($doc);
> //$tables = $xpath->query('//table');
> //print $tables
>
> // courtesy:
> // &#34;Dennis Shearin&#34;
> //04-Jul-2007 04:17
> //http://php.benscom.com/manual/fr/function.dom-domelement-construct.php
> function nodeDump($node)
> {
> $output = print_r($node, TRUE);
> $output = str_replace(")\n", '', $output);
> $output .= ' ' . '[tagName] => ' . $node->tagName . " \n";
>
> $numOfAttribs = $node->attributes->length;
> for ($i = 0; $i < $numOfAttribs; $i++)
> {
> $output .= ' [' . $node->attributes->item($i)->nodeName . ']
> => ' . $node->attributes->item($i)->nodeValue . " \n";
> }
>
> $output .= ' [nodeValue] => ' . $node->nodeValue;
> $output .= ')';
> return $output;}
>
> ?>
>
> --
> // This is my opinion.

 

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

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