成长,总在点滴之间

将中文字符串分割为数组 解决str_split中文乱码php

  /**
     * 将字符串分割为数组
     * @param  string $str 字符串
     * @return array       分割得到的数组
     */
    function mb_str_split($str){
        return preg_split('/(?<!^)(?!$)/u', $str );
    }
    $str='明天上午十七点提醒我带早餐';
    mb_str_split($str);
    打印结果如下:
    array:13 [
      0 => "明"
      1 => "天"
      2 => "上"
      3 => "午"
      4 => "十"
      5 => "七"
      6 => "点"
      7 => "提"
      8 => "醒"
      9 => "我"
      10 => "带"
      11 => "早"
      12 => "餐"
    ]