Groups
Groups
Sign in
Groups
Groups
thinkinlamp
Conversations
About
Send feedback
Help
请教大家一个关于php字符串查找与替换来过滤垃圾信息的问题
19 views
Skip to first unread message
Sm Liu
unread,
Oct 5, 2012, 5:43:47 PM
10/5/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to think...@googlegroups.com
str_replace函数因为不兼容双字节,所以查找时经常出现故障,查了一下百度,看到有人说使用mb_ereg_replace函数,但是我用这个函数经常出现明明有敏感字符,却出现无法过滤的情况,不知道是什么原因?
$newinfo='惠州有小q姐包夜Q服務电话182xxxxxxx8';
$tmpstr=mb_ereg_replace('務', '', $newinfo);
这样执行出来的结果却是$tmpst和$newinfo是同样的,没法过滤掉那个“務”字,正确的写法应该是怎么样的呢?
Jie Hu
unread,
Oct 6, 2012, 6:00:05 AM
10/6/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to think...@googlegroups.com
不知道mb_substr之類的方法可以用不?指定編碼看看是否能匹配到。
--
ThinkingInLAMP邮件组使用说明:
http://blog.thinkinlamp.com/?p=758
Marvin Ma
unread,
Oct 6, 2012, 7:29:37 AM
10/6/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to think...@googlegroups.com
如果你是UTF8编码的话,可以用 preg_replace() 来实现:
$newinfo='惠州有小q姐包夜Q服務电话182xxxxxxx8';
$re = preg_replace("/務/u", "", $newinfo);
print_r($re);
2012/10/6 Jie Hu
<
xsi...@gmail.com
>
--
ThinkingInLAMP邮件组使用说明:
http://blog.thinkinlamp.com/?p=758
--
Best Regards,
Marvin Ma
QQ:397337097 Sina:@三马 Tel:15921270388
童中波
unread,
Oct 6, 2012, 11:18:57 AM
10/6/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to think...@googlegroups.com
估计原因是编码不一致。
两种解决方案:
1.确定要过滤的文字$newinfo的编码,然后将敏感字符"務"转成相同编码,再进行过滤
2.如果不好确定过滤文字编码,将敏感字符转成各种可能编码,再进行过滤
2012/10/6 Marvin Ma
<
samo...@gmail.com
>
--
童中波
工程帅/研发中心-WEB研发部
湖北盛天网
络技术股份有限公司
Hubei Century Network Technology Co., Ltd.
Fax: (86-27) 8749 8500
Add:
武汉市东湖高新技术开发区国际企业中心2期1栋
Zip code: 430074
http://www.stnts.com
Reply all
Reply to author
Forward
0 new messages