v0.7.5 - Added helpers to support substr closetag function
This commit is contained in:
parent
2aaadd00b0
commit
17434eb81d
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
public static function closetags($html) {
|
||||
preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
|
||||
$openedtags = $result[1];
|
||||
preg_match_all('#</([a-z]+)>#iU', $html, $result);
|
||||
$closedtags = $result[1];
|
||||
$len_opened = count($openedtags);
|
||||
if (count($closedtags) == $len_opened) {
|
||||
return $html;
|
||||
}
|
||||
$openedtags = array_reverse($openedtags);
|
||||
for ($i=0; $i < $len_opened; $i++) {
|
||||
if (!in_array($openedtags[$i], $closedtags)) {
|
||||
$html .= '</'.$openedtags[$i].'>';
|
||||
} else {
|
||||
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue