note 40271 deleted from function.domnode-replace-child by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:41:43 +0000 |
| Subject: | note 40271 deleted from function.domnode-replace-child by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207412@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at fivetide dot com
----
There's a bug in the docs here. The order of arguments is the other way round i.e.
object DomNode->replace_child ( object newnode, object oldnode)
Here's an example of it working:
<?php
$doc = domxml_new_doc("1.0");
$root = $doc->create_element("HTML");
$doc->append_child($root);
$head = $doc->create_element("HEAD");
$root->append_child($head);
$title = $doc->create_element("TITLE");
$head->append_child($title);
$text = $doc->create_text_node("This is the title");
$title->append_child($text);
echo "<PRE>";
echo htmlentities($doc->dump_mem(true));
echo "</PRE>";
$newtitle = $doc->create_text_node("No, this is the title");
// object DomNode->replace_child ( object newnode, object oldnode)
$title->replace_child($newtitle,$title->first_child());
echo "<PRE>";
echo htmlentities($doc->dump_mem(true));
echo "</PRE>";
?>