从PHP字符串中剥离除字母数字字符外的所有内容 [英] Stripping everything but alphanumeric chars from a string in PHP
本文介绍了从PHP字符串中剥离除字母数字字符外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个正则表达式或其他字符串,该字符串可以替换字符串中字母数字字符(a-z
和0-9
)以外的所有内容.诸如,@#$(@*810
之类的所有内容都应删除.有什么想法吗?
I'd like a regexp or other string which can replace everything except alphanumeric chars (a-z
and 0-9
) from a string. All things such as ,@#$(@*810
should be stripped. Any ideas?
现在我需要用它来去除除点以外的所有内容,因此除a-z, 1-9, .
以外的所有内容.想法?
I now need this to strip everything but allow dots, so everything but a-z, 1-9, .
. Ideas?
推荐答案
$string = preg_replace("/[^a-z0-9.]+/i", "", $string);
匹配一个或多个非a-z 0-9(不区分大小写)或."的字符.并替换为"
Matches one or more characters not a-z 0-9 [case-insensitive], or "." and replaces with ""
这篇关于从PHP字符串中剥离除字母数字字符外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文