Why is PHP's explode wrong?

Here is the PHP code:

var_dump($value);
string(103) "0e0cUZ‚dddd.is.moar.awesome‚A6A32C2074B787893DF506F6F466F5919516C44F3"
var_dump(explode(',', $value));
array(1) {
  [0]=>
  string(103) "0e0cUZ‚dddd.is.moar.awesome‚A6A32C2074B787893DF506F6F466F5919516C44F3"
}

Why isn't the string being split on the comma?


Because the character in the string you're trying to explode() is not a comma – well, not an ASCII comma: , (decimal code point 44 ). The comma in the string is a Unicode Character 'SINGLE LOW-9 QUOTATION MARK' (decimal code point 8218 ).

Try this in your JavaScript console:

> '‚' === ','
  false

After a lot of investigation, the real problem was that the input string was in the Windows-1252 encoding. Therefore trying to replace U+201A didnt work until I converted it to unicode first.

链接地址: http://www.djcxy.com/p/92674.html

上一篇: 使用PHP的`list`函数被认为是不好的做法?

下一篇: 为什么PHP的爆炸错误?