Split Chinese string into an array solve str_split Chinese garbled php

Source: Internet
Author: User
Tags arrays

First, we introduce the function of Str_split ().

Its role is to split the string into arrays;

For example:

$str = ' ABCDE ';
Str_plite ($STR);

The results printed are as follows:
Array
(
[0] => a
[1] => b
[2] => C
[3] => D
[4] => E
)

It seems to be very easy to use, but as a Chinese programmer, it is inevitable to deal with Chinese;

At this time again with Str_splite will be tragic found garbled;;

Don't be afraid; Preg_splite can save the problem;

Of course, it needs to be used in conjunction with regular use;

/**
* Splits a string into
arrays * @param string $STR strings
* @return Array split-
function Mb_str_spl It ($STR) {return
preg_split (? <!^) (?! $/U ', $str);

$str = ' Bai Jun remote blog ';
Mb_str_split ($STR);

The results are as follows:
Array
(
[0] => white
[1] => June
[2] => remote
[3] => bo
[4] => guest
)

To finish a call;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.