How to split Chinese characters in PHP?

前端 未结 3 1586
南笙
南笙 2021-01-03 13:13

I need some help regarding how to split Chinese characters mixed with English words and numbers in PHP.

For example, if I read

FrontPage 2000中文版應用大全
         


        
3条回答
  •  醉梦人生
    2021-01-03 13:55

    With this code you can make chinese text (utf8) to wrap at the end of the line so that it is still readable

    print_r(preg_match_all('/([\w]+)|(.)/u', $str, $matches));
    $arr_result = array();
    
    foreach ($matches[0] as $key => $val) {
        $arr_result[]=$val;
        $arr_result[]="​"; //add Zero-Width Space
    } 
    foreach ($arr_result as $key => $val) {
        $out .= $val;
    } 
    return $out;
    

提交回复
热议问题