PHP konvertiert einen String in ein Array, unterstützt Chinesisch
/** * 将一个字符串转换成数组,支持中文 * @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; }
Verwendung:
$string = '这里就是要转换成数组的字符串,www.liqingbo.cn'; $arr = strToArray($string); print_r($arr);
Ausgabe:
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 )