可能重复:
preg_replace all but numbers, letters, periods, and slash?
我有一个字符串,我想从该字符串替换所有字符除了:
答案 0 :(得分:4)
简单Preg_Replace,空字符串:
preg_replace('/[^\w@,.;]/', '', $string);
[^] represents a list of characters NOT to match
\w Word character (abcABC0-9_)
,.; as the characters themselves
答案 1 :(得分:2)
怎么样:
preg_replace('/[^\pL\pN@,.;]+/', '', $string);
\pL
是字母
的unicode属性
\pN
是数字的unicode属性