Problems with regular matching pattern modifier lowercase u php

Source: Internet
Author: User
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 ...
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.