Last active
July 3, 2018 03:06
-
-
Save tieutantan/b82c9010bc393512c0b67d4a75e9769a to your computer and use it in GitHub Desktop.
Function get content for package "paquettg/php-html-parser"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* https://github.com/paquettg/php-html-parser */ | |
public static function get_content(string $html_identity, string $needed_attribute, $source_html) | |
{ | |
$dom = new \PHPHtmlParser\Dom; | |
$dom->load($source_html); | |
$array_content = []; | |
foreach ($dom->find($html_identity) as $content) | |
{ | |
if ($needed_attribute == 'text') { | |
$array_content[] = strip_tags($content->outerHtml); | |
} elseif ($needed_attribute == 'html') { | |
$array_content[] = $content->outerHtml; | |
} else { | |
// get content of Attribute name | |
$array_content[] = $content->getAttribute($needed_attribute); | |
} | |
} | |
return (empty($array_content)) ? false : array_unique($array_content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment