dongtan7639 2011-02-20 21:03
浏览 24

带有Unicode字符的php preg_replace

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, letters and Unicode (non-latin) letters and numbers (I think, I should use the Unicode values of this (for example U+1F70)).

What can I do? Thanks ...

  • 写回答

1条回答 默认 最新

  • dougu4027 2011-02-20 21:09
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)