preg_match与国际字符和重音符号 [英] preg_match with international characters and accents
本文介绍了preg_match与国际字符和重音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用只能包含字母(包括带有重音符号的字母)的模式来验证字符串.这是我使用的代码,它始终返回"nok". 我不知道我在做什么错,您能帮忙吗?谢谢
I would like to validate a string with a pattern that can only contain letters (including letters with accents). Here is the code I use and it always returns "nok". I don't know what I am doing wrong, can you help? thanks
$string = 'é';
if(preg_match('/^[\p{L}]+$/i', $string)){
echo 'ok';
} else{
echo 'nok';
}
推荐答案
Add the UTF-8 modifier flag (u) to your expression:
/^\p{L}+$/ui
也不需要将\p{L}
包装在字符类中.
There is also no need to wrap \p{L}
inside of a character class.
这篇关于preg_match与国际字符和重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文