Skip to content

Commit

Permalink
fix: MD\Util\Helper->getTextBetweenTags(): return empty array if inpu…
Browse files Browse the repository at this point in the history
…t string is empty + do not throw error
  • Loading branch information
e-picas committed Feb 24, 2024
1 parent 7f101f6 commit 89d0ec9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/MarkdownExtended/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ public static function isSingleLine($str = '')
*/
public static function getTextBetweenTags($string, $tagname)
{
$d = new \DOMDocument();
$d->loadHTML($string);
$return = [];
foreach($d->getElementsByTagName($tagname) as $item) {
$return[] = $item->textContent;
if (empty($string)) {
return $return;
}
$d = new \DOMDocument();
try {
$d->loadHTML($string);
foreach($d->getElementsByTagName($tagname) as $item) {
$return[] = $item->textContent;
}
} catch (\ErrorException $e) {
}
return $return;
}
Expand Down

0 comments on commit 89d0ec9

Please sign in to comment.