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

search for in the

DomNode->replace_node> <DomNode->remove_child
Last updated: Fri, 14 Nov 2008

view this page in

DomNode->replace_child

(No version information available, might be only in CVS)

DomNode->replace_child 子ノードを置換する

説明

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

(PHP 4.2) この関数は子ノード oldnode を渡された新規ノードに置換します。もし新規ノードがすでに子ノードの場合、 二度目は追加されません。もし古いノードが存在しない場合、 この関数は FALSE を返します。もし置換が成功した場合、 古いノードが返されます。

(PHP 4.3) この関数は新規ノードがすでに DomNode の子ノードだったとしても、 子ノード oldnode を渡された newnode に置換します。 もし newnode ガスでに文章に挿入されている場合、 最初に既存のコンテキストから削除されます。 もし古いノードが存在しない場合、この関数は FALSE を返し、 置換が成功した場合は古いノードが返されます (この動作は W3C 規格に準拠しています。)

domnode_append_child() も参照ください。



add a note add a note User Contributed Notes
DomNode->replace_child
nospam at fivetide dot com
27-Feb-2004 03: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>";
?>

DomNode->replace_node> <DomNode->remove_child
Last updated: Fri, 14 Nov 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites