Split utf8 string into array of chars

后端 未结 6 1885
别那么骄傲
别那么骄傲 2021-01-14 05:26

I\'m trying to split a utf8 encoded string into an array of chars. The function that I now use used to work, but for some reason it doesn\'t work anymore. W

6条回答
  •  花落未央
    2021-01-14 05:48

    This is the best solution!:

    I've found this nice solution in the PHP manual pages.

    preg_split('//u', $str, null, PREG_SPLIT_NO_EMPTY);
    

    It works really fast:

    In PHP 5.6.18 it split a 6 MB big text file in a matter of seconds.

    Best of all. It doesn't need MultiByte (mb_) support!

    Similar answer also here.

提交回复
热议问题