Php5.3.5preg _ matchBUG! Solution

Source: Internet
Author: User
Php5.3.5preg _ matchBUG !!! Environment & nbsp; window + php3.35 + apache2.2 today I am writing & nbsp; When I use regular expressions to verify the user name, there is no problem in Chinese or English, but & nbsp; when registering with this word, besides the problem echo & nbsp; preg_match ([& nbsp;], net), the file is UTF-8 php 5.3.5 preg_match BUG !!!
// Environment window + php3.35 + apache2.2
Chinese and English are all correct when I write a regular expression to verify the user name.

However, this word is used for registration, except for the problem.

Echo preg_match ("/[\ '\" \]/"," ");

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


Under normal circumstances, 0 should be output, right, but the output is 1. you can try it!

How can this problem be solved!

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.

However, the BUG you mentioned does not exist.
In the regular expression string, [] is a single character list, while the full-width space is multiple characters.
You need at least u modifiers.
Echo preg_match ("/[\ '\" \]/u "," ");

------ Solution --------------------
The problem lies in [\ '\ "\]. the last blank space is a multi-byte character % E3 % 80% 80
The net character is encoded as % E5 % 87% 80
There are 80 duplicates between the two, so they will match the same byte.
------ Solution --------------------
Reference:
The problem lies in [\ '\ "\]. the last blank space is a multi-byte character % E3 % 80% 80
The net character is encoded as % E5 % 87% 80
There are 80 duplicates between the two, so they will match the same byte.


+ 1
Match by byte without the unicode modifier
So % 80 bingo!
------ Solution --------------------
Reference:
Baidu: u is greedy. can you explain why?

Why is there no error in other Chinese characters, but this word "net?

You are wrong! U is greedy mode switch
While u is in UTF-8 correction mode. In this mode, any UTF-8 character is processed as a 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.