Home > php教程 > php手册 > php 字符串截取函数

php 字符串截取函数

WBOY
Release: 2016-06-13 11:19:12
Original
896 people have browsed it

本文章介绍的是php自带的一个截取字符串的函数,只能处理英文,数字的不能截取中文混排的哦,有需要的朋友可以参考,后面的比较好用,第一个主要是给初学者学学用的。  

 代码如下 复制代码
/*
------------------------------------------------------
参数:
$str_cut    需要截断的字符串
$length     允许字符串显示的最大长度

程序功能:截取全角和半角(汉字和英文)混合的字符串以避免乱码
------------------------------------------------------
*/
function substr_cut($str_cut,$length)
{
    if (strlen($str_cut) > $length)
    {
        for($i=0; $i         if (ord($str_cut[$i]) > 128)    $i++;
        $str_cut = substr($str_cut,0,$i)."..";
    }
    return $str_cut;
}
?>


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template