PHP preg_match 语言相关解释错误
Posted
技术标签:
【中文标题】PHP preg_match 语言相关解释错误【英文标题】:PHP preg_match language dependent interpretation error 【发布时间】:2020-08-25 15:40:42 【问题描述】:不支持土耳其语字符 Ş İ Ö Ü 等。我累了。
<?php
header('Content-Type: text/html; charset=utf-8');
$test = "azAZ09andSpace supported but this turkish characters Ş İ Ö Ü like not supported";
//So it goes to the "else block".
if (preg_match('/^[a-zA-Z0-9 ]+$/', $test))
echo "match";
else
echo "not match"; //return false. Because Ş İ Ö Ü like not supported
?>
【问题讨论】:
我不知道PHP是否使用PCRE,但它绝对不使用Perl。固定标签。 不,我只想添加土耳其语字符。'/^[a-zA-Z0-9 Letter]+$/'
应该是这样吗?
preg_match('/^[a-zA-Z0-9\pL ]+$/u', $test)
非常非常非常!谢谢@ikegami。
【参考方案1】:
\pL
匹配任何字母(包括重音字母),因此您可以使用以下内容:
preg_match('/^[\pL0-9 ]+$/u', $test)
同样,\d
匹配任何数字,\s
匹配任何空格字符,因此您也可以使用以下内容:
preg_match('/^[\pL\d\s]+$/u', $test)
【讨论】:
以上是关于PHP preg_match 语言相关解释错误的主要内容,如果未能解决你的问题,请参考以下文章