Completed
Push — master ( c39a14...8d69cc )
by Lars
02:07
created

example_remove_comments.php ➔ html_no_comment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
use voku\helper\HtmlDomParser;
4
5
require_once '../vendor/autoload.php';
6
7
function html_no_comment(string $html): string
8
{
9
    // create HTML DOM
10
    $dom = \voku\helper\HtmlDomParser::str_get_html($html);
11
12
    // remove all comment elements
13
    foreach ($dom->find('comment') as $e) {
14
        $e->outertext = '';
15
    }
16
17
    return $dom->save();
18
}
19
20
// -----------------------------------------------------------------------------
21
22
$html = '
23
<p>lall<br></p>
24
<!-- comment -->
25
<ul><li>test321<br>test123</li><!----></ul>
26
';
27
28
// html without comments
29
echo html_no_comment($html);
30