Regular match pattern modifier lowercase u problem php

Source: Internet
Author: User
Tags php regular expression
Recently seen a piece of code:
 
  ";  ? >

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


Reply to discussion (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

\w is extended to Chinese characters by the original [_0-9a-za-z],
\w matches any number, letter, underline, what does it mean to extend to Chinese characters?

$s = ' Kanji abc ';p reg_match_all ('/\w/', $s, $r); No U-Modified print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = a
[1] = b
[2] = C
)

)
$s = ' Kanji abc ';p reg_match_all ('/\w/u ', $s, $r); There are U-modified print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = Han
[1] = Word
[2] = a
[3] = b
[4] = C
)

)

$s = ' Kanji abc ';p reg_match_all ('/\w/', $s, $r); No U-Modified print_r ($R);
Have
Array
(
[0] = = Array
(
[0] = a
[1] = b
[2] = C
)

)
$s = ' Kanji abc ';p reg_match_all ('/\w/u ', $s, $r); There are U-modified 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 ...

Thank the moderator, understand ...

  • 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.