preg_replace:通配符与元音变音字符不匹配
我想使用 \w 通配符来过滤字符串,但不幸的是它不涵盖变音符号。
$i = "Die Höhe";
$x = preg_replace("/[^\w\s]/","",$i);
echo $x; // "Die Hhe";
但是,我可以将所有字符添加到 preg_replace 中,但这不是很优雅,因为列表会变得很长。 ATM,我只为德语准备这个,但还会有更多语言。
$i = "Die Höhe";
$x = preg_replace("/[^\w\säöüÄÖÜß]/","",$i);
echo $x; // "Die Höhe";
有没有办法同时匹配所有这些?
i want to filter a String by using the \w wildcard, but unfortunately it does not cover umlauts.
$i = "Die Höhe";
$x = preg_replace("/[^\w\s]/","",$i);
echo $x; // "Die Hhe";
However, i can add all the characters to preg_replace, but this is not very elegant, since the list will become very long. ATM, i am preparing this only for German, but there are more languages to come.
$i = "Die Höhe";
$x = preg_replace("/[^\w\säöüÄÖÜß]/","",$i);
echo $x; // "Die Höhe";
Is there a way to match all of them at once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的字符串显然是 UTF-8,因此您需要 'u' 标志和 unicode 属性而不是 \w
You strings are obviously UTF-8, so you want the 'u' flag and unicode properties instead of \w
在我看来,这应该删除所有无意义的字符:
this should remove all, in my opinion, non meaningful chars: