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.