dongyipa0028 2012-04-17 13:25
浏览 110
已采纳

php preg_split和UTF-8符号

Could anybody explain, why this code

$string='6аd_ТЕХТ GOOD_TEXT';
$words = preg_split('/\s+/', $string, NULL, PREG_SPLIT_NO_EMPTY);

var_dump($words);

displays

array(2) { [0]=> string(8) "6àd_ÒÅÕÒ" [1]=> string(9) "GOOD_TEXT" }

instead of

array(2) { [0]=> string(8) "6аd_ТЕХТ" [1]=> string(9) "GOOD_TEXT" }

I've read about this issue, but adding /u :

preg_split('/\s+/', $string, NULL, PREG_SPLIT_NO_EMPTY);// '/\s+/'

to become

preg_split('/\s+/u', $string, NULL, PREG_SPLIT_NO_EMPTY);// '/\s+/u'

doesn't help. How to fix this issue?

Thank you.

  • 写回答

2条回答 默认 最新

  • douxu4610 2012-04-17 13:56
    关注

    There is something else happening in your code that isn't present in the provided example. Tested the provided example and it works as expected. On the off-chance that this is really happening (and there is no other code affecting $string), this may be a bug with the specific PHP version you're using and can be solved by upgrading PHP (but it's highly unlikely that it's an issue with PHP).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部