PHP Classes

File: example/example_add_content.php

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

Contents

Class file image Download
<?php

use voku\helper\HtmlDomParser;

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

$templateHtml = '<ul><li>test321</li></ul>';

// add: "<br>" to "<li>"
$htmlTmp = HtmlDomParser::str_get_html($templateHtml);
foreach (
$htmlTmp->findMulti('ul li') as $li) {
   
$li->innerhtml = '<br>' . $li->innerhtml . '<br>';
}
foreach (
$htmlTmp->findMulti('br') as $br) {
   
// DEBUG:
   
echo $br->tag; // br
}

$templateHtml = $htmlTmp->save();

// dump contents
echo $templateHtml; // <ul><li><br>test321<br></li></ul>