PHP: DomNode->replace_child - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DomNode->replace_node DomNode->remove_child

Last updated: Fri, 26 Jan 2007

view this page in

# DomNode->replace_child

(no version information, might be only in CVS)

DomNode->replace_child -- Replaces a child

## Описание

domelement DomNode->replace_child ( domelement newnode, domelement oldnode )

(PHP 4.2) This function replaces the child `oldnode` with the passed new node. If the new node is already a child it will not be added a second time. If the old node cannot be found the function returns `FALSE`. If the replacement succeeds the old node is returned.

(PHP 4.3) This function replaces the child `oldnode` with the passed `newnode`, even if the new node already is a child of the DomNode. If `newnode` was already inserted in the document it is first unlinked from its existing context. If the old node cannot be found the function returns `FALSE`. If the replacement succeeds the old node is returned. (This behaviour is according to the W3C specs).

See also domnode_append_child()

add a note User Contributed Notes
DomNode->replace_child
nospam at fivetide dot com
26-Feb-2004 06:25
`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>";
?>`
add a note
DomNode->replace_node DomNode->remove_child

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST