Regular match pattern modifier lowercase u problem php
Recently seen a piece of code:
$str = ' Hello, world dd ';
Preg_match_all ('/./us ', $str, $match);
echo Count ($match [0]). "
";
?>
On the internet to check a lot of information, but for the PHP regular expression pattern modifier u really some do not understand, solve ah ...
Share to: more
------Solution--------------------
The u:unicode abbreviation, which indicates that the string to be matched is a string conforming to the Unicode encoding rules, such as a utf-8 encoded string
Under the U modifier, a kanji is treated as a character. \w has the original [_0-9a-za-z] extended to Chinese characters
------Solution--------------------
$s = ' Chinese abc ';
Preg_match_all ('/\w/', $s, $r); No U-Decoration
Print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = a
[1] = b
[2] = C
)
)
$s = ' Chinese abc ';
Preg_match_all ('/\w/u ', $s, $r); With U-modifier
Print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = Han
[1] = Word
[2] = a
[3] = b
[4] = C
)
)
------Solution--------------------
References:
$s = ' Chinese abc ';
Preg_match_all ('/\w/', $s, $r); No U-Decoration
Print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = a
[1] = b
[2] = C
)
)
$s = ' Chinese abc ';
Preg_match_all ('/\w/u ', $s, $r); With U-modifier
Print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = Han
[1] = Word
[2] = a
[3] = b
[4] = C
)
)
Moderators greatly write a suitable for beginners to learn the regular bar.
Is there a big difference between. NET Regular and PHP?
Http://deerchao.net/tutorials/regex/regex.htm
This person writes. NET easy to understand, ask moderator greatly similar to a ...