PHP Classes

File: example/example_modify_attribute.php

Recommend this page to a friend!
  Classes of Lars Moelleken  >  Simple HTML DOM  >  example/example_modify_attribute.php  >  Download  
File: example/example_modify_attribute.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple HTML DOM
Manipulate HTML elements using DOMDocument
Author: By
Last change: Update of example/example_modify_attribute.php
Date: 10 months ago
Size: 554 bytes


Class file image Download

use voku\helper\HtmlDomParser;


$html = '<html><div id="p1" class="post">foo</div><div class="post" id="p2">bar</div></html>';

$document = new HtmlDomParser($html);

foreach (
$document->find('div') as $e) {
$attrs = array();
    foreach (
$e->getAllAttributes() as $attrKey => $attrValue) {
$attrs[$attrKey] = $attrValue;
$e->$attrKey = null;


    foreach (
$attrs as $attrKey => $attrValue) {
$e->$attrKey = $attrValue;


For more information send a message to info at phpclasses dot org.