2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > PHP截取固定长度字符串函数

PHP截取固定长度字符串函数

时间:2019-08-28 09:37:44

相关推荐

PHP截取固定长度字符串函数

<?php functiontoFixLen($str,$len){//固定长度字符串的截取 if($len>=strlen($str)||!$len)return$str; $len-=3; $tempstr1=substr($str,0,$len);//截取字符串 $tempstr2=preg_replace('/([/x81-/xff]+)$/ms','',$tempstr1,1);//去掉结尾的连续汉字字符 if(!is_int((strlen($tempstr1)-strlen($tempstr2))/2)){//去掉的字符为奇数? $tempstr1=substr($str,0,$len-1); } return$tempstr1."…"; } ?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。