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

search for in the

DOMElement::removeAttributeNode> <DOMElement::hasAttributeNS
[edit] Last updated: Mon, 20 May 2013

view this page in

DOMElement::removeAttribute

(PHP 5)

DOMElement::removeAttributeEfface un attribut

Description

bool DOMElement::removeAttribute ( string $name )

Efface l'attribut nommé name de l'élément.

Liste de paramètres

name

Le nom de l'attribut.

Valeurs de retour

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

Erreurs / Exceptions

DOM_NO_MODIFICATION_ALLOWED_ERR

Lancé si le noeud est en lecture seule.

Voir aussi



add a note add a note User Contributed Notes DOMElement::removeAttribute - [3 notes]
up
0
sanu_imtiaz at yahoo dot com
5 days ago
when i am trying to delete the Attribute by using RemoveAttribute property.
It didnt delete it.

For example:
$node->removeAttribute('src');
   
instead of the above following code works:
 $node->nodeValue='';
whats the reason??
up
0
suwayan at mail dot ru
1 year ago
<?php
/*When I try to get a some attribute from not validated HTML or XML document, PHP dies with no errors in logs or output:
*/
       
function is_attribute_value($obj,$type,$value)
        {
           
$_ret=false;
            if(
$obj)
            {
                if(
$val=$obj->getAttribute($type))
                {
                    if(
$val==$value)
                    {
                       
$_ret=true;
                    }
                }
            }
            return
$_ret;
        }
//And this check helped to me:
       
function is_attribute_value($obj,$type,$value)
        {
           
$_ret=false;
            if(
$obj->attributes)
            {
                if(
$val=$obj->getAttribute($type))
                {
                    if(
$val==$value)
                    {
                       
$_ret=true;
                    }
                }
            }
            return
$_ret;
        }
?>
up
0
Rakesh Verma - rakeshnsony at gmail dot com
2 years ago
<?php

//Store your html into $html variable.

$html="<html>
<head>
<title>Rakesh Verma</title>
</head>

<body>
    <a href='http://example.com'>Example</a>
    <a href='http://google.com'>Google</a>
    <a href='http://www.yahoo.com'>Yahoo</a>
</body>

</html>"
;

$dom = new DOMDocument();
$dom->loadHTML($html);

//Evaluate Anchor tag in HTML
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

for (
$i = 0; $i < $hrefs->length; $i++) {
       
$href = $hrefs->item($i);
       
$url = $href->getAttribute('href');

       
//remove and set target attribute       
       
$href->removeAttribute('target');
       
$href->setAttribute("target", "_blank");

       
$newURL=$url.".au";

       
//remove and set href attribute       
       
$href->removeAttribute('href');
       
$href->setAttribute("href", $newURL);
}

// save html
$html=$dom->saveHTML();

echo
$html;

?>

 
show source | credits | sitemap | contact | advertising | mirror sites