PHP: RegEx vs. ctype_ *

A few months ago, you provided the perfect solution for my IsAlpha and co problems. But again, I ran into problems after updating PHP (to version 5.2.9), although the ctype_ * functions seem to be doing 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)

For questions, I mean that "GB" or "blablue" is correctly identified as alpha ctype_alpha(), but with an error preg_match("/^[\p{L} _.\-]+$/u", $value).

Please let me know if you have any ideas, I ran out of them after a serious search.

Many, many thanks!

PS LANG/ LC_CTYPE/ etc is installed en_US.UTF-8in both environments

+3
source share
2 answers

, PCRE UTF-8, Unicode.

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.';

http://github.com/kohana/kohana/blob/master/install.php.

+4

, . : . , , , .

-1

Source: https://habr.com/ru/post/1726182/


All Articles