Heim  >  Artikel  >  Backend-Entwicklung  >  怎样用php写个函数,要求是超过3个连续相同的字符会被过滤成两个,用正则式也行!解决方法

怎样用php写个函数,要求是超过3个连续相同的字符会被过滤成两个,用正则式也行!解决方法

WBOY
WBOYOriginal
2016-06-13 10:08:181077Durchsuche

怎样用php写个函数,要求是超过3个连续相同的字符会被过滤成两个,用正则式也行!
比如像“好好好”,被过滤成“好好”,像“非常好非常好非常好”,被过滤成“非常好非常好”,像“,,,”被过滤成“,,”,像“~~~~~~~~~”被过滤成“~~”,尽可能多把所有可能性包含进去!最近在玩wordpress,想避免尽可能多的垃圾无意义评论~

------解决方案--------------------

探讨

引用:

echo preg_replace("/(.+)\\1+/is", '$1$1', $s);

但不知 ~~~~~~~~~ 为何不能被处理

.+?应该可以

------解决方案--------------------
探讨

引用:

引用:

echo preg_replace("/(.+)\\1+/is", '$1$1', $s);

但不知 ~~~~~~~~~ 为何不能被处理

.+?应该可以
开玩笑吧?
PHP code
$s =比如像“好好好”,被过滤成“好好”,像“非常好非常好非常好”……

------解决方案--------------------
哈哈,我记性还行....

http://topic.csdn.net/u/20100302/22/A86F914D-AC19-4955-BC98-768C584EA800.html#r_63678078
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn