PHP: RegEx vs. ctype_*
several months ago, you provided a perfect solution for my IsAlpha & co issues. But once again, I ran into issues after upgrading PHP (to version 5.2.9), although the ctype_* functions seem to do their job now:
ctype_alpha( $value ) /* VS */ preg_match("/^[\p{L} _.\-]+$/u", $value)
ctype_alnum( $value ) /* VS */ preg_match("/^[\p{L}0-9 _.\-]+$/u", $value)
By issues, I mean that 'GB' or 'blablue' is i.e. correctly identified as alpha by ctype_alpha()
, but fails with preg_match("/^[\p{L} _.\-]+$/u", $value)
.
Please let me know if you have any ideas, I ran out of them after some serious googling..
Many, many thanks!
P.S. LANG
/LC_CTYPE
/et开发者_运维知识库c is set to en_US.UTF-8
both on both environments
Make sure PCRE has been compiled with UTF-8 support as well as Unicode property support.
if ( ! @preg_match('/^.$/u', 'ñ'))
echo 'PCRE has not been compiled with UTF-8 support.';
if ( ! @preg_match('/^\pL$/u', 'ñ'))
echo 'PCRE has not been compiled with Unicode property support.';
Checks from http://github.com/kohana/kohana/blob/master/install.php.
I had some issue with a regex using unicode metacharacters on a hosting server. Issue in short: it doesn't work. I didn't investigate on the true cause since it was a temporary server, but you might look into unicode support as your problem seems similar.
精彩评论