note 93755 added to domdocument.registernodeclass
| From: | crh3675 at gmail dot com | Date: | Sat, 26 Sep 2009 03:23:46 +0000 |
| Subject: | note 93755 added to domdocument.registernodeclass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161091@lists.php.net to get a copy of this message | ||
Creating innerHTML and outerHTML
<?php
class DOMHTMLElement extends DOMElement
{
function __construct() { parent::__construct();}
public function innerHTML()
{
$doc = new DOMDocument();
foreach ($this->childNodes as $child){
$doc->appendChild($doc->importNode($child, true));
}
$content = $doc->saveHTML();
return $content;
}
public function outerHTML()
{
$doc = new DOMDocument();
$doc->appendChild($doc->importNode($this, true));
$content = $doc->saveHTML();
return $content;
}
}
$dom = DOMDocument::loadHTMLFile($file);
$dom->registerNodeClass('DOMElement','DOMHTMLElement');
if($dom)
{
$xpath = new DOMXpath($dom);
$regions = $xpath->query("//*[contains(@class, 'editable')]");
$content = '';
foreach($regions as $region){
$content .= $region->outerHTML();
}
return $content;
}else{
throw new Exception('Cannot parse HTML. Please verify the syntax is correct.');
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.246.217.210
----
Manual Page -- http://www.php.net/manual/en/domdocument.registernodeclass.php
Edit -- https://master.php.net/note/edit/93755
Del: integrated -- https://master.php.net/note/delete/93755/integrated
Del: useless -- https://master.php.net/note/delete/93755/useless
Del: bad code -- https://master.php.net/note/delete/93755/bad+code
Del: spam -- https://master.php.net/note/delete/93755/spam
Del: non-english -- https://master.php.net/note/delete/93755/non-english
Del: in docs -- https://master.php.net/note/delete/93755/in+docs
Del: other reasons-- https://master.php.net/note/delete/93755
Reject -- https://master.php.net/note/reject/93755
Search -- https://master.php.net/manage/user-notes.php