dongyipa0028 2012-04-17 21: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 21: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条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)