aboutsummaryrefslogtreecommitdiff
path: root/app/model/HTMLExtract.php
blob: b2ab39efed532329ba28affef4e6a2602266485b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

class DOMExtract extends DOMDocument
{
    private $document;

    public function __construct()
    {
        libxml_use_internal_errors(true);
        $this->preserveWhiteSpace = false;
        $this->strictErrorChecking = false;
        $this->formatOutput = false;
    }

    public function innerHTML($tag, $file)
    {
        $html = '';
        $this->loadHTML(file_get_contents($file));
        $this->document = $this->getElementsByTagName($tag);

        foreach ($this->document as $node)
        {
            /*
            |  TODO: DOMDocument::saveHTML's empty elements list is not updated.
            |  https://bugs.php.net/bug.php?id=73175
            */

            $html .= $this->saveHTML($node);
        }

        return str_replace("</source>", '', $html);
    }
}