我正在运行一个WordPress插件,它处理内容并在X个段落之后插入一些东西。现在我的代码非常野蛮。样本:
$del = '</p>';
$para_count = substr_count($html, $del);
if($para_count == 0) {
$del = "\r\n\r\n";
$para_count = substr_count($html, $del); # echo "1";
}
if($para_count == 0) {
$del = "\n\n\n\n";
$para_count = substr_count($html, $del); # echo "2";
}
if($para_count == 0) {
$del = '
';
$para_count = round(substr_count($html, $del) / 2); # echo "3";
}
if($para_count == 0) {
$del = '<br/><br/>';
$para_count = substr_count($html, $del); # echo "4";
}
if($para_count == 0) {
$del = '<br><br>';
$para_count = substr_count($html, $del); # echo "5";
}
if($para_count == 0) {
$del = '<br /><br />';
$para_count = substr_count($html, $del); # echo "6";
}
if($para_count == 0) {
return "<div class='display:none'><!-- NO DELIMETER FOUND --></div>".$html;
}
当来源未知时,找到段落分隔符的最佳方法是什么?我可以将脚本缩减为更简单的代码吗?