Home > php教程 > PHP源码 > body text

中文字符串分割

PHP中文网
Release: 2016-05-23 17:10:14
Original
1451 people have browsed it


/**
 * Convert a string to an array
 * @param string $str
 * @param number $split_length
 * @return multitype:string
 */
function mb_str_split($str,$split_length=1,$charset="UTF-8"){
    if(func_num_args()==1){
        return preg_split(&#39;/(?<!^)(?!$)/u&#39;, $str);
    }
    if($split_length<1)return false;
    $len = mb_strlen($str, $charset);
    $arr = array();
    for($i=0;$i<$len;$i+=$split_length){
        $s = mb_substr($str, $i, $split_length, $charset);
        $arr[] = $s;
    }
    return $arr;
}
Copy after login

                   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!