人氣點閱:6345 |
發表人 |
PHP: str_split_unicode/str_split_utf8 Split UTF8 Character 2014-09-22 00:03 |
/ / /
|
|
PHP: str_split_unicode() str_split_utf8() Split UTF8 Character into Array
See example php code below. (PHP 5.X)
e.g. Explodes/splits string '你好' into array('你, '好');
代碼:
<?PHP
// REF: http://us.php.net/str_split
function str_split_unicode($str, $l = 0)
{
if ($l > 0) {
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l) {
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}
$a = 'ㄕㄨ'; // BPMF ZH_TW UTF8/Unicode character
$aa = str_split_unicode($a);
$aaa = str_split($a);
var_dump($a);
var_dump($aa);
var_dump($aaa);
?>
代碼:
$ php str_split_utf8.php
string(6) "ㄕㄨ"
array(2) {
[0]=>
string(3) "ㄕ"
[1]=>
string(3) "ㄨ"
}
array(6) {
[0]=>
string(1) "▒"
[1]=>
string(1) "▒"
[2]=>
string(1) "▒"
[3]=>
string(1) "▒"
[4]=>
string(1) "▒"
[5]=>
string(1) "▒"
}
________________
美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
|
|
Type
繪圖畫廊 設計藝廊 攝影相簿 留言板 最愛收藏 分類標籤
暱稱: Type 註冊: 2002-11-30 發表: 11172 來自: vovo2000.com
V幣: 901758
|
|
|
|
|