PHP 5.6.16 is available


(PHP 5, PHP 7)

DOMElement::removeAttributeNodeEfface un attribut


public bool DOMElement::removeAttributeNode ( DOMAttr $oldnode )

Efface l'attribut oldnode de l'élément.

Liste de paramètres


Le noeud de l'attribut.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès ou FALSE si une erreur survient.

Erreurs / Exceptions


Lancé si le noeud est en lecture seule.


Lancé si oldnode n'est pas un attribut de l'élément.

Voir aussi

add a note add a note

User Contributed Notes 1 note

xr07354 at gmx dot de
2 years ago
Basic: I use PHP5.4.9 from Ubuntu 13.04 repository. The aim of my code is to iterate HTML source (as a DomDocument) recursively and cleanup everything that is not valid to be used inside Epub files (i.e. and attribute align is not valid for paragraphs in Epubs).

FIRST: Today I tried removing attributes from a DOMElement using this simple code:
for ( $k=0; $k < $element->attributes->length; $k++) {
/* some rule */ ){
var_dump( $element->attributes->item($k)->nodeName);
$element->removeAttributeNode( $element->attributes->item($k));
Unfortunately all attributes still existed when this loop was finished, even if these var_dumps told me that deleting them was tried.

I solved this problem iterating the attributes list backward:
for ( $k = $element->attributes->length - 1; $k >= 0; --$k) {
/* same rule */ ){
var_dump( $element->attributes->item($k)->nodeName);
$element->removeAttributeNode( $element->attributes->item($k));
SECOND: DOMElement::removeAttributeNode does NOT return a bool but a DOMAttr object.
To Top