0
从字符串中删除空html标记的最快方法是什么?使用PHP检查和删除空标记
我已经设定这样的事情来检测空锚标签:
$temp = strip_tags($string, "<blockquote><a>");
$cmatch = array();
if(preg_match_all("~<a.*><\/a>~iU", $temp, $cmatch, PREG_SET_ORDER))
{
foreach($cmatch as $cm)
{
foreach($cm as $t) //echo htmlentities($t)."<br />";
$temp = trim(str_replace($t, '', $temp));
}
}
if(!empty($temp))
{
echo '<div class="c" style="margin-top:20px;">';
echo $temp;
echo '</div>';
}
//do not output if empty tags (problem with div margin)
必须能够有效地做到这一点了。将字符串转换为html DOM并在那里检查会更快吗?