Extract required data from html source
@param $html
@return array
490279
protected function parseHtml($html)
    {
        $data = [
            'image' => '',
            'title' => '',
            'description' => '',
            'pictures' => [],
        ];

        libxml_use_internal_errors(true);
        $doc = new \DOMDocument();
        $doc->loadHTML($html);

        /** @var \DOMElement $meta */
        foreach ($doc->getElementsByTagName('meta') as $meta) {
            if ($meta->getAttribute('itemprop') === 'image') {
                $data['image'] = $meta->getAttribute('content');
            } elseif ($meta->getAttribute('property') === 'og:image') {
                $data['image'] = $meta->getAttribute('content');
            } elseif ($meta->getAttribute('property') === 'twitter:image') {
                $data['image'] = $meta->getAttribute('value');
            }

            if ($meta->getAttribute('itemprop') === 'name') {
                $data['title'] = $meta->getAttribute('content');
            } elseif ($meta->getAttribute('property') === 'og:title') {
                $data['title'] = $meta->getAttribute('content');
            } elseif ($meta->getAttribute('property') === 'twitter:title') {
                $data['title'] = $meta->getAttribute('value');
            }

            if ($meta->getAttribute('itemprop') === 'description') {
                $data['title'] = $meta->getAttribute('content');
            }
            if ($meta->getAttribute('property') === 'og:description') {
                $data['description'] = $meta->getAttribute('content');
            }
        }

        if (empty($data['title'])) {
            /** @var \DOMElement $title */
            foreach ($doc->getElementsByTagName('title') as $title) {
                $data['title'] = $title->nodeValue;
            }
        }

        if (empty($data['description'])) {
            foreach ($doc->getElementsByTagName('meta') as $meta) {
                if ($meta->getAttribute('name') === 'description') {
                    $data['description'] = $meta->getAttribute('content');
                }
            }
        }

        foreach ($doc->getElementsByTagName('img') as $img) {
            $data['pictures'][] = $img->getAttribute('src');
        }

        return $data;
    }
201682
public function readability_html( $html )
	{
		$data = $this->post_call('/readability', ['html' => $html ] );

		return ( !empty($data['readability']) ) ? $data['readability'] : null;
	}
1099768
public function getMethods($html = true)
    {

        $arr = Array();

        foreach($this->served_classes as $class){
            foreach (\get_class_methods($class) as $method) {

                $reflect = new \ReflectionMethod($class, $method);

                if ($reflect) {
                    
                    if($class == $this){
                        $docs = $reflect->getDocComment();
                        $servable = false;
                        if (!empty($docs)) {
                            if (\preg_match("~@servable (true|false)~", $docs, $match)) {
                                $servable = $match[1] == 'true' ? true : false;
                            }
                        }
                    } else if($reflect->isPublic()){
                        $servable = true;
                    }
                    
                    if (!$servable) {
                        continue;
                    }

                    $params = $reflect->getParameters();
                    $ps = Array();
                    foreach ($params as $param) {
                        $ps[] = '$' . $param->getName();
                    }

                    $key = $method . '(' . implode(', ', $ps) . ')';

                    $arr[$key] = $reflect->getDocComment();
                }
            }
        }
        

        if ($html == false) {
            return $arr;
        } else {
            return $this->methodsToHtml($arr);
        }
    }
221572
public function htmlToElement($html)
    {
        // Buffer engine used to convert the html string into DOMElements,
        $fabrication = new FabricationEngine;
        $fabrication->run($html);

        // Retrive xpath element from the FabricationEngine.
        $element = $this->query('//html/body')->item(0);

        // Append the new DOM Element(s) to the found DOMElement.
        $element->appendChild(
                $this->importNode(
                        $fabrication->query($this->xpath . '/*')->item(0)
                        , true
                )
        );

        return $element;
    }
1357190
public function prepareHtml($html)
    {
        // if it is a real html page, we have to convert it
        if (preg_match('/<body/isU', $html)) {
            $html = $this->getHtmlFromRealPage($html);
        }

        // replace some constants
        $html = str_replace('[[date_y]]', date('Y'), $html);
        $html = str_replace('[[date_m]]', date('m'), $html);
        $html = str_replace('[[date_d]]', date('d'), $html);

        $html = str_replace('[[date_h]]', date('H'), $html);
        $html = str_replace('[[date_i]]', date('i'), $html);
        $html = str_replace('[[date_s]]', date('s'), $html);

        return $html;
    }
116761
public function parseString($html)
    {
        /** TODO: custom markdown-extra options, e.g. titles & classes **/
        // <sup id="fnref:..."><a href"#fn..." rel="footnote">...</a></sup>
        // => <fnref target="..." />
        $html = preg_replace('@<sup id="fnref:([^"]+)">\s*<a href="#fn:\1" rel="footnote">\s*\d+\s*</a>\s*</sup>@Us', '<fnref target="$1" />', $html);
        // <div class="footnotes">
        // <hr />
        // <ol>
        //
        // <li id="fn:...">...</li>
        // ...
        //
        // </ol>
        // </div>
        // =>
        // <footnotes>
        //   <fn name="...">...</fn>
        //   ...
        // </footnotes>
        $html = preg_replace_callback('#<div class="footnotes">\s*<hr />\s*<ol>\s*(.+)\s*</ol>\s*</div>#Us', [&$this, '_makeFootnotes'], $html);

        return parent::parseString($html);
    }
1070321
private function parseContents(string $html): string
    {
        if (\trim($html) === '') {
            return '';
        }

        // Determine value.
        $this->value = $html;
        if (\preg_match("/(.*)<\/\s*" . $this->name . "\s*>/iU", $html, $valueMatches) === 1) {
            $this->value = $valueMatches[1];
        }

        // Don't parse contents of "iframe" element.
        if ($this->name === 'iframe') {
            return $this->parseNoContents('iframe', $html);
        }

        // Only TEXT inside a "script" element.
        if ($this->name === 'script') {
            return $this->parseForeignContents('script', $html);
        }

        // Only TEXT inside a "style" element.
        if ($this->name === 'style') {
            return $this->parseForeignContents('style', $html);
        }

        // Parse contents one token at a time.
        $remainingHtml = $html;
        while ($this->isAnotherTokenPresent($remainingHtml)) {
            $token = Tokenizer::buildFromHtml($remainingHtml, $this);

            if (!$token instanceof TokenInterface || $token->isClosingElementImplied($remainingHtml)) {
                return $remainingHtml;
            }

            $remainingHtml = $token->parse($remainingHtml);
            $this->children[] = $token;
        }

        $this->removeLastTokenIfContainsOnlyWhitespace();

        // Remove remaining closing tag.
        $posOfClosingBracket = \mb_strpos($remainingHtml, '>');

        return \mb_substr($remainingHtml, $posOfClosingBracket + 1);
    }
874853
public function extractLinks()
    {
        if ($this->extractedLinks) {
            return $this->extractedLinks;
        }

        if (!is_html($this->body)) {
            return [];
        }

        $libxmlPreviousState = libxml_use_internal_errors(true);

        $dom = new DOMDocument;
        $dom->loadHTML($this->body);

        libxml_clear_errors();
        libxml_use_internal_errors($libxmlPreviousState);

        $links = [];

        foreach ($this->tags as $tag => $attribute) {
            foreach ($dom->getElementsByTagName($tag) as $element) {
                $link = $element->getAttribute($attribute);

                if (!$link) {
                    continue;
                }

                $links[] = clean_url(url_to_absolute($this->url, $link), true, true);
            }
        }

        return $this->extractedLinks = array_unique($links);
    }
651861
private function extractMetas(DOMDocument $html)
    {
        foreach ($html->getElementsByTagName('meta') as $meta) {
            $value = $meta->getAttribute('content');

            if (empty($value)) {
                continue;
            }

            if ($meta->hasAttribute('name')) {
                $name = trim(strtolower($meta->getAttribute('name')));

                switch ($name) {
                    case 'msapplication-tileimage':
                        $this->bag->add('icons', $value);
                        continue 2;

                    default:
                        $this->bag->set($name, $value);
                        continue 2;
                }
            }

            if ($meta->hasAttribute('itemprop')) {
                $this->bag->set($meta->getAttribute('itemprop'), $value);
            }

            if ($meta->hasAttribute('http-equiv')) {
                $this->bag->set($meta->getAttribute('http-equiv'), $value);
            }

            if ($meta->hasAttribute('property')) {
                $this->bag->set($meta->getAttribute('property'), $value);
            }
        }
    }
580811
private function extractOpenGraph($html, $baseUrl)
    {
        if ('' === trim($html)) {
            return [];
        }

        libxml_use_internal_errors(true);

        $doc = new \DomDocument();
        $doc->loadHTML($html);

        libxml_use_internal_errors(false);

        $xpath = new \DOMXPath($doc);
        $query = '//*/meta[starts-with(@property, \'og:\')]';
        $metas = $xpath->query($query);

        $rmetas = [];
        foreach ($metas as $meta) {
            $property = str_replace(':', '_', $meta->getAttribute('property'));

            if ('og_image' === $property) {
                // avoid image data:uri to avoid sending too much data
                // also, take the first og:image which is usually the best one
                if (0 === stripos($meta->getAttribute('content'), 'data:image') || !empty($rmetas[$property])) {
                    continue;
                }

                $rmetas[$property] = $this->makeAbsoluteStr($baseUrl, $meta->getAttribute('content'));

                continue;
            }

            $rmetas[$property] = $meta->getAttribute('content');
        }

        return $rmetas;
    }
1222630
final public function importHTML($html)
	{
		$tmp_doc = new \DOMDocument('1.0', 'UTF-8');
		$tmp_doc->loadHTML($html);
		$nodes = array();
		foreach ($tmp_doc->documentElement->childNodes as $node) {
			array_push($nodes, $node);
			$this->appendChild($this->ownerDocument->importNode($node, true));
		}
		return $nodes;
	}
573904
public function parse($html)
    {
        $xp = $this->getXpathFromHtml($html);
        $table = $xp->query('./html/body/table[1]');

        if (0 == $table->length) {
            return false;
        }

        $nodes = $table->item(0)->childNodes;
        $dic = $this->getKeyValues($nodes, $xp);

        return $dic;
    }
812897
public function loadHTML($html)
    {
        $dom = new \DOMDocument();

        libxml_use_internal_errors(true);
        $dom->loadHTML($html, LIBXML_NOWARNING);
        $errors = libxml_get_errors();
        libxml_use_internal_errors(false);

        // Run through all errors
        /** @var \LibXMLError $error */
        foreach ($errors as $error) {
            throw new InvalidArgumentException(
                sprintf(InvalidArgumentException::INVALID_HTML_STR, trim($error->message)),
                InvalidArgumentException::INVALID_HTML
            );
        }

        return $dom;
    }
979683
function parseString($html) {
    $this->parser->html = $html;
    $this->parse();
    return $this->output;
  }
499080
public static function getConstants($html = false)
	{
		$result = [];
		foreach ((new \ReflectionClass(get_class()))->getConstants() as $constant) {
			$key = static::$cssPrefix . ' ' . static::$cssPrefix . '-' . $constant;

			$result[$key] = ($html)
				? static::icon($constant) . '&nbsp;&nbsp;' . $constant
				: $constant;
		}

		return $result;
	}
282432
protected function getHtmlRootElement($html)
    {
        $html = trim($html);
        if ($html === '') {
            return null;
        }
        $domDocument = new \DOMDocument('1.0', 'UTF-8');
        // ignore parsing errors
        $useInternalErrorsBackup = libxml_use_internal_errors(true);
        $domDocument->loadHTML($html);
        $xPath = new \DOMXPath($domDocument);
        $rootElement = $xPath->query('//html/body/*');
        if ($useInternalErrorsBackup !== true) {
            libxml_use_internal_errors($useInternalErrorsBackup);
        }
        if ($rootElement === false || $rootElement->length !== 1) {
            return null;
        }
        // detect whether loadHTML has wrapped plaintext in a p-tag without asking for permission
        if ($rootElement instanceof \DOMNodeList && $rootElement->item(0)->tagName === 'p' && preg_match('/^<p/ui', $html) === 0) {
            return null;
        }
        return $rootElement->item(0);
    }
1273117
public static function createLinks($html)
    {
        return preg_replace_callback(
            '!((?:https?\://|\b\www\.).*?)([.,;:]( |$|<)|[ <]|$)!',
            function ($m) {
                $url = $m[1];
                $html = $m[1];
                if (!preg_match('/^https?:/', $url)) {
                    $url = 'http://' . $url;
                }
                return sprintf('<a href="%s">%s</a>%s', $url, $html, $m[2]);
            },
            $html
        );
    }