PHP - 替换所有支持的语言的所有非字母数字字符 [英] PHP - replace all non-alphanumeric chars for all languages supported

查看:41
本文介绍了PHP - 替换所有支持的语言的所有非字母数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上正在尝试从这样的字符串中替换所有非字母数字字符:

Hi i'm actually trying replacing all the NON-alphanumeric chars from a string like this:

mb_ereg_replace('/[^a-z0-9\s]+/i','-',$string);

第一个问题是它不会从字符串中替换像 "." 这样的字符.

first problem is it doesn't replaces chars like "." from the string.

其次,我想为此方法添加对所有用户语言的多位支持.

Second i would like to add multybite support for all users languages to this method.

我该怎么做?

任何帮助appriciated,非常感谢.

Any help appriciated, thanks a lot.

推荐答案

尝试以下操作:

preg_replace('/[^\p{L}0-9\s]+/u', '-', $string);

u 标志用于正则表达式时,\p{L}(和 \p{Letter})匹配任何任何 Unicode 字母类别中的字符.

When the u flag is used on a regular expression, \p{L} (and \p{Letter}) matches any character in any of the Unicode letter categories.

这篇关于PHP - 替换所有支持的语言的所有非字母数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆