PHP Classes
elePHPant
Icontem

File: example/example_remove_comments.php

Recommend this page to a friend!
  Classes of Lars Moelleken  >  Simple HTML DOM  >  example/example_remove_comments.php  >  Download  
File: example/example_remove_comments.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 month ago
Size: 550 bytes
 

 

Contents

Class file image Download
<?php


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

function
html_no_comment(string $html): string
{
   
// create HTML DOM
   
$dom = \voku\helper\HtmlDomParser::str_get_html($html);

   
// remove all comment elements
   
foreach ($dom->find('comment') as $e) {
       
$e->outertext = '';
    }

    return
$dom->save();
}

// -----------------------------------------------------------------------------

$html = '
<p>lall<br></p>
<!-- comment -->
<ul><li>test321<br>test123</li><!----></ul>
'
;

// html without comments
echo html_no_comment($html);