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