PHP
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, 18 Jul 2008

view this page in

DomNode->replace_child

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

DomNode->replace_child — Sostituisce un nodo figlio

Descrizione

object DomNode->replace_child ( object $vecchio_nodo , object $nuovo_nodo )

(PHP 4.2) Questa funzione sostituisce il nodo vecchio_nodo con il parametro nuovo_nodo. Se il nuovo nodo è già un figlio questo non verrà aggiunto una seconda volta. Se la funzione non riesce a trovare il vecchio nodo, restituisce FALSE. Se, invece, la sostituzione riesce, la funzione restituisce il vecchio nodo.

(PHP 4.3) Questa funzione sostituisce il nodo figlio vecchio_nodo con il parametro nuovo_nodo , anche se il nuovo nodo è già un figlio di DomNode. Se nuovo_nodo era già presente nel documento, prima questo viene rimosso dal contesto esistente. Se la funzione non riesce a trovare il vecchio nodo, restituisce FALSE. Se la sostituzione riesce, la funzione restituisce il vecchio nodo. (Questo comportamento rispecchia le specifiche W3C).

Vedere anche domnode_append_child()



add a note 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>";
?>

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