PHP preg_replace(从字符串中替换除字母、数字和少数字符之外的所有字符)


PHP preg_replace (replace from string all characters except letters, numbers, and few characters)

可能重复:
preg_replace除了数字、字母、句点和斜线之外的所有内容?

我有一个字符串,我想从该字符串中替换除之外的所有字符

  • 所有字母
  • 所有数字
  • @

简单预处理替换为空字符串:

preg_replace('/[^'w@,.;]/', '', $string);
[^] represents a list of characters NOT to match
'w Word character (abcABC0-9_)
,.; as the characters themselves

怎么样:

preg_replace('/[^'pL'pN@,.;]+/', '', $string);

'pL是字母的unicode属性
'pN是数字的unicode属性