2012-04-13 67 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); 
的情况下,
相关问题