教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php中文字符截取函数(自用)

php中文字符截取函数(自用)

发布时间:2016-11-10   编辑:jiaochengji.com
本文介绍下,php中用于中文字符截取的一个函数,有需要的朋友参考下。

分享一个自己一直在用的PHP中文字符截取函数,很不错,有用到的朋友拿去吧。

代码:

<?php
/**
* @ 中文字符截取
* @ site:www.jbxue.com
*/
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;
}
?>

您可能感兴趣的文章:
php 字符截取中文防乱码用.chr(0)
php函数substr 截取中文字符出现乱码
php 中文截取字符串 mb_substr的用法
php 截取中文的函数utf_substr
php substr截断中文半个汉字乱码问题
php 截取中文字符串乱码
php 截取中文字符(utf-8格式)的函数
四个php 中文字符串截取函数
php 中文字符串截取 php截取中文字符串的函数
php 中文字符串截取(mb_substr)实例

您可能感兴趣的文章:
php中文字符截取函数(自用)
php截取字符串(无乱码 utf8)
php如何截取字符串后四位
php中文截取字符串函数(很好用)
php 字符串截取函数(可以自动清除网页标签)
php中文截取字符串mb_substr的用法
php中文字符串截取方法
php截取字符串实例代码
php截取中文字符串的二个函数(iconv_substr和mb_substr)
php中英文混排字符串截取方法

关键词: 截取  字符串截取   
[关闭]
~ ~