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
 

Contents

Class file image Download
<?php

use voku\helper\HtmlDomParser;

require_once
'../vendor/autoload.php';

$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;
    }

   
ksort($attrs);

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

echo
$document->html();

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