PHP:如何爆炸()中文字符串

Hello I have this string

$chineseString = "号码:91"

What I want to do is to explode() it and get a result like this:

array:2[
 [0] => "号码",
 [1] => "91"
]

The reason explode() didn't work for you is that your chineseString variable contains what is called in unicode a FULLWIDTH COLON (U+FF1A) and you are trying to split by a different character, a COLON (U+003A). So, if you use the correct character it will work.

$chineseString = "号码:91";
print_r(explode(":", $chineseString ));

Outputs: Array([0] => 号码, [1] => 91)

This seems to work for me:

$chineseString = "号码:91";
print_r(preg_split('/:/', $chineseString));

Results in: Array ( [0] => 号码 [1] => 91 )

Take a look at this http://codepad.org/yYO3nljF

 <?php

    $chineseString = "号码:91";
    $d = explode(":",$chineseString );
    var_dump($d);

    ?>

output

array(2) {
  [0]=>
  string(6) "号码"
  [1]=>
  string(2) "91"
}