PHP将一个字符串转换成数组,支持中文/**
* 将一个字符串转换成数组,支持中文
* @param string $string 待转换成数组的字符串
* @return string 转换后的数组
*/
function strToArray($string) {
$strlen = mb_strlen($string);
while ($strlen) {
$array[] = mb_substr($string, 0, 1, "utf8");
$string = mb_substr($string, 1, $strlen, "utf8");
$strlen = mb_strlen($string);
}
return $array;
}
用法:$string = '这里就是要转换成数组的字符串,';
$arr = strToArray($string);
print_r($arr);
输出:Array
(
[0] => 这
[1] => 里
[2] => 就
[3] => 是
[4] => 要
[5] => 转
[6] => 换
[7] => 成
[8] => 数
[9] => 组
[10] => 的
[11] => 字
[12] => 符
[13] => 串
[14] => ,
[15] => w
[16] => w
[17] => w
[18] => .
[19] => l
[20] => i
[21] => q
[22] => i
[23] => n
[24] => g
[25] => b
[26] => o
[27] => .
[28] => c
[29] => n
)
相关标签:php
发布php中文网,转载请注明出处,感谢您的尊重!
如果觉得《php 将一个字符串转换成数组 PHP将一个字符串转换成数组》对你有帮助,请点赞、收藏,并留下你的观点哦!