输入banner图图片脚本导航/分类

php字符串截取小例子php函数截取固定长度字符串

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