2012-04-13 64 views
0

我試圖用PHP過濾公開提交的內容,以防止人們在其內容的末尾添加太多時間段。將超時期的實例替換爲單個…實體

提交的內容可能是這個網站的形式:

<p>Hi Jummy. I haz the lolz...............</p> 
<h3>Yeah.... <a href="/foo">dem lolz are funny</a>..</h3> 

理想情況下,我想下面的規則

1 period = left alone 
2 periods = 1 period 
2+ periods = &hellip; 

所以上面的例子來代替過長的情況下,會變成:

<p>Hi Jummy. I haz the lolz&hellip;</p> 
<h3>Yeah&hellip; <a href="/foo">dem lolz are funny</a>.</h3> 

非常感謝

回答

2

首先,更換所有的三個或多個週期

$content = preg_replace('/\.{3,}/', '&hellip;', $content); 

然後情況下,更換兩個時期

$content = str_replace('..', '.', $content); 
的情況下,
相關問題