PHP字符串preg_replace,保留奇怪的字母和数字

Jen*_*ell 0 php regex preg-replace

我想把这些字母和数字保存在一个字符串中

  • åäö和其他奇怪的信件
  • az和其他普通字母
  • 123和其他数字

我不想要这个

  • ##¤&#!.,_-和其他奇怪的人物

$content = preg_replace("???", "", $string);
Run Code Online (Sandbox Code Playgroud)

Cas*_*yte 5

您可以使用Jonny 5方法来编写字符类中所需的所有字符.您可以使用\p{Latin}包含所有拉丁字母的预定义类(以及重点字母):

$content = preg_replace('~[^\p{Latin}0-9]+~u', '', $string); 
Run Code Online (Sandbox Code Playgroud)

如果你想要"世界"的所有字母或数字:

$content = preg_replace('~\P{Xan}+~u', '', $string); 
Run Code Online (Sandbox Code Playgroud)