PHP 8.5.0 Alpha 4 available for testing

Voting

: eight plus zero?
(Example: nine)

The Note You're Voting On

cemkalyoncu at gmail dot com
16 years ago
If you need some function to clone a node without touching namespaces you can use the following.

<?php
private function cloneNode($node,$doc){
$nd=$doc->createElement($node->nodeName);

foreach(
$node->attributes as $value)
$nd->setAttribute($value->nodeName,$value->value);

if(!
$node->childNodes)
return
$nd;

foreach(
$node->childNodes as $child) {
if(
$child->nodeName=="#text")
$nd->appendChild($doc->createTextNode($child->nodeValue));
else
$nd->appendChild(cloneNode($child,$doc));
}

return
$nd;
}
?>

<< Back to user notes page

To Top