时间:2021-07-01 10:21:17 帮助过:29人阅读
http://www.3qphp.com/index/show/index/184.html
$strleng)return
$str;//字符串长度小于规定字数时,返回字符串本身
$notchinanum = 0;//初始不是汉字的字符数
for($i=0;$i<$cutleng;$i++)
{
if(ord(substr($str,$i,1))<=128)
{
$notchinanum++;
}
}
if(($cutleng%2==1)&&($notchinanum%2==0))//如果要截取奇数个字符,所要截取长度范围内的字符必须含奇数个非汉字,否则截取的长度加一
{
$cutleng++;
}
if(($cutleng%2==0)&&($notchinanum%2==1))//如果要截取偶数个字符,所要截取长度范围内的字符必须含偶数个非汉字,否则截取的长度加一
{
$cutleng++;
}
return substr($str,0,$cutleng);
}
?>点击查看展开的全文
以上就介绍了php限制文章内容显示字数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。