This article introduces a function used to intercept Chinese characters in php. Friends in need can refer to it.
Share a PHP Chinese character interception function that I have been using. It is very good. Friends who use it can take it.
Code:
<?php /** * @ 中文字符截取 * @ site:bbs.it-home.org */ function str_cut($string, $length, $dot = ”) { if(strlen($string) <= $length) { return $string; } $strcut = ”; for($i = 0; $i < $length - strlen($dot) - 1; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } return $strcut.$dot; } ?>