1

Can someone explain why all this code works normally if PHP is only supposed to support a 256-character set?

I know that Content-Type tag interpret these characters if is on UTF-8. But why PHP work it?

echo "匝";

if (preg_match('/啊/', "啊"))
    echo "Match";

if (preg_match('/\w/', "啊"))
    echo "Match";
6
  • Does your PHP configuration have the mbstring (multibyte string) extension enabled? Commented Jul 6, 2011 at 2:17
  • one line says ;mbstring.strict_encoding = Off i dont know if the one that you are talking about Commented Jul 6, 2011 at 2:23
  • Where is the reference that says PHP only supports 256 character set? Never mind, found it, php.net/manual/en/language.types.string.php Commented Jul 6, 2011 at 2:32
  • It seems that exist packages to support 256 up characters but not much info. i think. Commented Jul 6, 2011 at 2:39
  • @nEAnnam: The semicolon is key -- it's a comment, so your parameter is "not off". Commented Jul 6, 2011 at 2:50

2 Answers 2

1

Compare your code to:

if (preg_match('/^\w$/', "啊"))
    echo "Match";

regex /\w/ works because your multibyte char contains of 2 bytes: 0x53 and 0x1D. And first one, 0x53 looks like a valid single-byte char S

PS: this is valid way to match one multibyte letter:

var_dump(preg_match('/^\p{L}$/u', "匝", $matches));
Sign up to request clarification or add additional context in comments.

3 Comments

So its not handling the character? its handle the bytes? why can be echoed? at the first sentence
@nEAnnam: it handles characters, supposing each char is single byte. Cannot get all your questions... It can be echoed - because you echo it.
lol, sorry yeah im thinking that its so useful your answer, ill compare a single byte from the char with the entire character
0

Most likely that your PCRE has been compiled with Unicode support enabled (--enable-utf8 --enable-unicode-properties) which would cause preg_match() to match unicode characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.