3v4l.org

run code in 300+ PHP versions simultaneously
<?php function cn_substr_utf8($str, $start=0,$length) { if(strlen($str) < $start+1) { return ''; } preg_match_all("/./su", $str, $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; } } } return $str; } $a = '测试这是一个测试'; $a = 'xxxxbbbbbnnn'; $b = cn_substr_utf8($a,0,6,'utf-8'); var_dump($b); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Optional parameter $start declared before required parameter $length is implicitly treated as a required parameter in /in/jr4DF on line 3 string(7) "xxxxbbb"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.86 ms | 401 KiB | 8 Q