PHP 5.3.5 Preg_match bug! Solution

Source: Internet
Author: User
PHP 5.3.5 preg_match BUG!!!
Environmental window+php3.35+apache2.2
Today, when I write a regular authentication user name, Chinese, English is not a problem

But when you sign up with this word, it's just a question.

Echo Preg_match ("/[\" \ "\ \]/", "net");

The file is Utf-8 also set the header ("Content-type:text/html;charset=utf-8");


Under normal circumstances, should output 0, right, but unexpectedly output for 1, we can try!

And how to solve this problem! PHP RegExp Reglur Regular


------Solution--------------------
It's not surprising that there are bugs! Because of this, PHP recommends that you upgrade to 5.3.22 or 5.4.12

But the bug you're talking about doesn't exist.
A list of single characters is in the [] of the regular rule string, and the full-width space is a multi-character
You need at least a U modifier
Echo Preg_match ("/[\" \ "\ \]/u", "net");

------Solution--------------------
The problem is in [\ ' \ ' \ \] and the last white space is a multibyte character%e3%80%80
And the net word is encoded as%e5%87%80
Between the two have theis duplicated, so it matches to the same byte
------Solution--------------------
Reference: The
problem is in [\ ' \ ' \ \], and the last blank is a multibyte character%e3%80%80
And the net word is encoded as%e5%87%80
There are 80 duplicates between the two, so it will match to the same byte


+1
Match by Byte without Unicode modifier
So%80 bingo!
------Solution--------------------
References:
Baidu a bit, U is greedy mode, can explain why?

And why the other Chinese characters are not wrong, but the "net" word?

You are wrong! U is greedy mode switch
and U is utf-8 correction mode. In this mode, any utf-8 characters are treated as one byte
  • 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.