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

WBOY
Release: 2016-06-13 10:08:18
Original
1077 people have browsed it

怎样用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
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!