为什么在多字节标点符号分割时会有一个额外的空行?

时间:2009-09-21 04:03:49

标签: php split multibyte

试试这个:

$pattern = '/[\x{ff0c},]/u';

//$string = "something here ; and there, oh,that's all!";
$string = 'hei,nihao,a ';


echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
exit();

输出:

<pre>Array
(
    [0] => hei,nihao,a
)
</pre>

1 个答案:

答案 0 :(得分:0)

您拥有的字符是全角逗号(hex ff0c),以及常规逗号。您是否尝试将其更新为我的版本?

<?php
$pattern = '/[\x{ff0c},]/u';

//$string = "something here ; and there, oh,that's all!";
$string = 'hei,nihao,a ';


echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';

输出:

Array
(
    [0] => hei
    [1] => nihao
    [2] => a 
)