3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php 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); } $s = '中华人民abc共和\x01国'; echo $s; print_r(str_split_unicode($s)); print_r(str_split_unicode($s, 3)); for($i =0 ; $i < len ; $i++) {echo $sub_str = mb_substr($s, $i, 1);}
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
中华人民abc共和\x01国Array ( [0] => 中 [1] => 华 [2] => 人 [3] => 民 [4] => a [5] => b [6] => c [7] => 共 [8] => 和 [9] => \ [10] => x [11] => 0 [12] => 1 [13] => 国 ) Array ( [0] => 中华人 [1] => 民ab [2] => c共和 [3] => \x0 [4] => 1国 ) Notice: Use of undefined constant len - assumed 'len' in /in/u4OLT on line 18
Output for 4.3.5 - 4.4.9
中华人民abc共和\x01国Array ( [0] => 中华人民abc共和\x01国 ) Array ( [0] => 中华人 [1] => 民ab [2] => c共和 [3] => \x0 [4] => 1国 ) Notice: Use of undefined constant len - assumed 'len' in /in/u4OLT on line 18
Output for 4.3.0 - 4.3.4
中华人民abc共和\x01国Array ( [0] => � [1] => � [2] => � [3] => � [4] => � [5] => � [6] => � [7] => � [8] => � [9] => � [10] => � [11] => � [12] => a [13] => b [14] => c [15] => � [16] => � [17] => � [18] => � [19] => � [20] => � [21] => \ [22] => x [23] => 0 [24] => 1 [25] => � [26] => � [27] => � ) Array ( [0] => 中华人 [1] => 民ab [2] => c共和 [3] => \x0 [4] => 1国 ) Notice: Use of undefined constant len - assumed 'len' in /in/u4OLT on line 18