Home  >  Article  >  Backend Development  >  PHP Chinese character interception function (for personal use)

PHP Chinese character interception function (for personal use)

PHP中文网
PHP中文网Original
2016-07-25 08:56:54939browse

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;
}
?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn