问题
I am going to build a multilingual website with PHP and need to have a preg_match which passes all Unicode characters and numbers.
i.e I need it to pass English letters, Spanish letters,Italian letters and as you may know I don't want to pass other characters like ' " _ - and ...
I want some thing like this :
$pattern='/^[unicode chars without \'-_;?]*$/u';
if(!preg_match($pattern, $url))
echo #error;
回答1:
Unicode property for letter is \pL
so in preg_match
:
preg_match('/^\pL+$/u', $string);
for an url you could add numbers \pN
and dot:
preg_match('/^[\pL\pN.]+/u', $string);
来源:https://stackoverflow.com/questions/10787029/how-can-i-use-preg-match-with-alphanumeric-and-unicode-acceptance