From: vtap at club-internet dot fr Operating system: Windows 7 RTM PHP version: 5.3.0 PHP Bug Type: DOM XML related Bug description: Counting and removing multiple attributes doesn't work
Description: ------------ Trying to remove all attributes of the <body> tag in an HTML file. 1/ Just counting : count is always equal to 1 whatever the real number of attributes is (varying from 0 to 3) though the name function retrieves all entries 2/ Removing : count is always equal to 1, only the first attribute is removed and breaks the loop, showing only the first one. Tried removeAttribute and removeAttributenode Reproduce code: --------------- $html = new DOMDocument(); $html -> loadHTMLFile("mypath\\myfile.html"); //Recherche du body et suppression de tous ses attributs $xpath = new DOMXPath($html); $query = "//body"; foreach ($xpath -> query($query) as $node) { echo "Count before = " . count($node-> attributes) . "<br />"; foreach ($node-> attributes as $attribute) { // $node-> removeAttributenode($attribute); echo "$attribute->name <br />"; // $node-> removeAttribute($attribute -> name); } echo "Count after = " . count($node-> attributes) . "<br />"; } Expected result: ---------------- <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> displays (just counting) Count before = 1 bgcolor text Count after= 1 displays (removing) Count before = 1 bgcolor Count after= 1 and gives <body text="#000000"> -- Edit bug report at http://bugs.php.net/?id=49835&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49835&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49835&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49835&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49835&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49835&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49835&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49835&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49835&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49835&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49835&r=support Expected behavior: http://bugs.php.net/fix.php?id=49835&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49835&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49835&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49835&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49835&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49835&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49835&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49835&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49835&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49835&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49835&r=mysqlcfg