php preg_replace with Unicode chars

前端 未结 1 1202
我寻月下人不归
我寻月下人不归 2021-01-16 11:59

I\'ve a question similar this question: php preg_replace

In that question, He/She want to allow only letters and numbers and _, but I want to allow only numbers, lett

相关标签:
1条回答
  • 2021-01-16 12:48

    Instead of listing the unicode ranges yourself, you should use an Unicode character class as explained here: http://www.regular-expressions.info/unicode.html#block

    preg_replace('/[^\w\d\p{L}]/u', "", $str);
    

    If you repeatedly try to construct or decipher regexps, don't forget to check out Is there anything like RegexBuddy in the open source world? for utilities that help with that.

    0 讨论(0)
提交回复
热议问题