|
Posted by jebblue on 11/15/07 04:26
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:
// "Dennis Shearin"
//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]
|