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に変換してチェックする方が速いでしょうか?非特異的な答えとして