php字符串截取小例子 php函数截取固定长度字符串
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-07-25 08:51:26
-
-
function toFixLen($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."…";
- }
- ?>
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
最新问题
-
2025-03-20 18:47:42
-
2025-03-20 18:47:05
-
2025-03-20 18:44:50
-
2025-03-20 18:44:11
-
2025-03-20 18:43:32