3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function cn_substr_utf8($str, $length, $start=0) { if(strlen($str) < $start+1) { return ''; } preg_match_all("/./su", $str, $ar); var_dump($ar); $str = ''; $tstr = ''; //为了兼容mysql教程4.1以下版本,与数据库教程varchar一致,这里使用按字节截取 for($i=0; isset($ar[0][$i]); $i++) { if(strlen($tstr) < $start) { $tstr .= $ar[0][$i]; } else { if(strlen($str) < $length + strlen($ar[0][$i]) ) { $str .= $ar[0][$i]; } else { break; } } } var_dump($tstr); return $str; } var_dump(); // $a = '测试这是一个测试'; $a = 'xxxxbbbbbnnn'; $b = cn_substr_utf8($a,5,0); var_dump($b); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: var_dump() expects at least 1 parameter, 0 given in /in/s0R5W on line 35 array(1) { [0]=> array(12) { [0]=> string(1) "x" [1]=> string(1) "x" [2]=> string(1) "x" [3]=> string(1) "x" [4]=> string(1) "b" [5]=> string(1) "b" [6]=> string(1) "b" [7]=> string(1) "b" [8]=> string(1) "b" [9]=> string(1) "n" [10]=> string(1) "n" [11]=> string(1) "n" } } string(0) "" string(6) "xxxxbb"
Output for hhvm-3.10.0 - 3.12.0
Warning: var_dump() expects exactly 1 parameter, 0 given in /in/s0R5W on line 35 array(1) { [0]=> array(12) { [0]=> string(1) "x" [1]=> string(1) "x" [2]=> string(1) "x" [3]=> string(1) "x" [4]=> string(1) "b" [5]=> string(1) "b" [6]=> string(1) "b" [7]=> string(1) "b" [8]=> string(1) "b" [9]=> string(1) "n" [10]=> string(1) "n" [11]=> string(1) "n" } } string(0) "" string(6) "xxxxbb"
Output for 4.3.0 - 5.2.17
Warning: Wrong parameter count for var_dump() in /in/s0R5W on line 35 array(1) { [0]=> array(12) { [0]=> string(1) "x" [1]=> string(1) "x" [2]=> string(1) "x" [3]=> string(1) "x" [4]=> string(1) "b" [5]=> string(1) "b" [6]=> string(1) "b" [7]=> string(1) "b" [8]=> string(1) "b" [9]=> string(1) "n" [10]=> string(1) "n" [11]=> string(1) "n" } } string(0) "" string(6) "xxxxbb"