importNode

From: Date: Thu, 02 Sep 2004 09:56:16 +0000
Subject: importNode
Groups: php.general 
Request: Send a blank email to php-general+get-195526@lists.php.net to get a copy of this message
I am trying to copy the body portion of a HTML file for use in the current page. I am using PHP 5.0.1. I think the following is close but not close enough; nothing gets imported by importNode. I assume this would be easy if I knew the DOM well enough; if someone else is then I hope this would be easy enough for them to either fix or provide something that works. <?php define("APPLICATION_ROOT", "C:/Apache2/htdocs/"); $Filename = "Categories.html"; if (!file_exists(APPLICATION_ROOT.$Filename)) { print "File $Filename does not exist<br>\n"; exit; } $Document = new DOMDocument(); $Document->loadHTMLFile(APPLICATION_ROOT.$Filename); if (!$Document) { echo "Error loading $Filename<br>\n"; exit; } $NewDocument = new DOMDocument(); $Body = $Document->getElementsByTagName("body")->item(0); foreach($Body->getElementsByTagName("*") as $Node) $NewDocument->importNode($Node, FALSE); print $NewDocument->saveHTML(); ?>

« previous php.general (#195526) next »