簡體   English   中英

嘗試刪除三個或更多 <br> 來自the_content

[英]Trying to remove three or more <br> from the_content

如標題所述,我正在嘗試從get_the_content();刪除並替換三個或更多<br> get_the_content(); 在我的single.php中。

我目前正在使用它,但是它似乎對文檔中<br>的數量沒有任何影響。

$content = get_the_content();
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
$content = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br /><br />', $content);
$content = strip_tags($content, '<br> <p> <a>');
echo $content; 

這給了我輸出:

<br />
<br />
<br />
<a href="http://1.bp.blogspot.com/-rYRPguEjEl8/UrSWUC_jEOI/AAAAAAAANm4/qVle4zdVfsQ/s1600/Alexa+NYC.jpg" imageanchor="1"></a>

<p>
<br />
<br />You don&#8217;t always have to stick to the same colour scheme 
<br />
<br />
<br />
<br />

我似乎無法使正則表達式正常工作。

試試這個代碼:

<?PHP
$input ="<br/><br/><br/><br/>Hello";
highlight_string($input);
$output = preg_replace('/(<br\s*\/?>\s*){3,}/', '<br/><br/>', $input);
highlight_string($output);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM