PHP截取固定长度字符串函数
<?php
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."…";
}
?>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/renren000/archive/2009/02/02/3858694.aspx
相关文档:
Blog系统作为大家最常接触的互联网东东,在站长群体中几乎人手一博,从知名门户的博客频道,到网络营销专家博客,网民对博客的关注度在不断提高并深化。目前网上免费的blog系统太杂,在此整理PHP版的Blog介绍如下:
1、wordpress:http://www.wordpress.org 功能也很全面,应该是支持blog的首选。它有最强的模版功能,已经 ......
<?php
/*
抛个砖,具体要做成什么样自己做。
*/
if(isset($_FILES['userfile']['tmp_name'])){
$userfile = $_FILES['userfile']['tmp_name']; //保存在系统的临时位置
$userfile_name = $_FILES['userfile']['name'];//文件名
$userfile_size = $_FILES['userfile'][ ......
将一个1维数组分割成2维数组 array_chunk()
$input_array = array('a', 'b', 'c', 'd', 'e');
print_r(array_chunk($input_array, 2));
比较2个数组,array_diff_assoc()或者array_diff(),如果返回值为空,表示两个数组相同,否则就不同。
用一个函数来过滤数组中的数值array_filter()
functi ......