DomNode->replace_child

(No version information available, 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()

[an error occurred while processing the directive]

Коментарии

Автор:
This function behaves differently depending on PHP version:

- It forgets attributes of the new node in PHP 5.2,
- but copies them in PHP 5.3.

(at least when looking at the SimpleXMLElement mirror of the DOM being changed in DOM (by lack of equivalent methods in SimpleXMLElement).

Annoying different behavior / bug, but good to know. Would be good to update the doc about what the wanted behavor is

In both versions, children nodes are not coming together with the new node and need to be added one by one recursively. Just good to know too.
2010-11-25 16:32:34
http://php5.kiev.ua/manual/ru/function.domnode-replace-child.html

    Поддержать сайт на родительском проекте КГБ