PHP开发过程中常用函数收藏


Posted in PHP onDecember 14, 2009

1.打印数组函数

function _print($array) 
{ 
echo ("<pre>"); 
print_r($array); 
echo ("</pre>"); 
}

2.截取字串
func_chgtitle 
function func_chgtitle($str,$len) 
{ 
if(strlen($str)>$len) 
{ 
$tmpstr = ""; 
$strlen = $len; 
for($i = 0; $i < $strlen; $i++) 
{ 
if(ord(substr($str, $i, 1)) > 0xa0) 
{ 
$tmpstr .= substr($str, $i, 2); 
$i++; 
} 
else 
$tmpstr .= substr($str, $i, 1); 
} 
return $tmpstr.""; 
} 
else 
{ 
return $str; 
} 
}

3.加载文件
loadFile 
function loadFile($filepath) 
{ 
$filecontent = ""; 
$fptr = fopen($filepath,"r"); 
if ($fptr) 
{ 
while ($content = fgets($fptr,4096)) 
{ 
$filecontent .= $content; 
} 
fclose($fptr); 
} 
return $filecontent; 
}

4.下载文件
downloadFile
function downloadFile($path,$fileInfo) 
{ 
$target_file = $path.$fileInfo['fileid']; 
$file_content = loadFile($target_file); 
header("Content-Disposition: attachment; filename=".$fileInfo['filename']); 
header("Content-type: ".$fileInfo['filetype']); 
header("Content-Length: ".$fileInfo['filesize']); 
echo $file_content; 
}

5.数组排序
/** 
* @package BugFree 
* @version $Id: FunctionsMain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss Exp $ 
* 
* 
* Sort an two-dimension array by some level two items use array_multisort() function. 
* 
* sysSortArray($Array,"Key1","SORT_ASC","SORT_RETULAR","Key2"……) 
* @author Chunsheng Wang <wwccss@263.net> 
* @param array $ArrayData the array to sort. 
* @param string $KeyName1 the first item to sort by. 
* @param string $SortOrder1 the order to sort by("SORT_ASC"|"SORT_DESC") 
* @param string $SortType1 the sort type("SORT_REGULAR"|"SORT_NUMERIC"|"SORT_STRING") 
* @return array sorted array. 
*/ 
function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR") 
{ 
if(!is_array($ArrayData)) 
{ 
return $ArrayData; 
} 
// Get args number. 
$ArgCount = func_num_args(); 
// Get keys to sort by and put them to SortRule array. 
for($I = 1;$I < $ArgCount;$I ++) 
{ 
$Arg = func_get_arg($I); 
if(!eregi("SORT",$Arg)) 
{ 
$KeyNameList[] = $Arg; 
$SortRule[] = '$'.$Arg; 
} 
else 
{ 
$SortRule[] = $Arg; 
} 
} 
// Get the values according to the keys and put them to array. 
foreach($ArrayData AS $Key => $Info) 
{ 
foreach($KeyNameList AS $KeyName) 
{ 
${$KeyName}[$Key] = $Info[$KeyName]; 
} 
} 
// Create the eval string and eval it. 
if(count($ArrayData)>0) 
{ 
$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);'; 
eval ($EvalString); 
} 
return $ArrayData; 
}

来源:http://www.cnblogs.com/xiaosuo/archive/2009/12/14/1594455.html
PHP 相关文章推荐
轻松修复Discuz!数据库
May 03 PHP
PHP采集利器 Snoopy 试用心得
Jul 03 PHP
新手学习PHP的一些基础知识分享
Jul 27 PHP
PHP变量的定义、可变变量、变量引用、销毁方法
Dec 20 PHP
php中fgetcsv()函数用法实例
Nov 28 PHP
php将textarea数据提交到mysql出现很多空格的解决方法
Dec 19 PHP
PHP中实现接收多个name相同但Value不相同表单数据实例
Feb 03 PHP
php中get_defined_constants函数用法实例分析
May 12 PHP
Yii2针对指定url的生成及图片等的引入方法小结
Jul 18 PHP
php成功操作redis cluster集群的实例教程
Jan 13 PHP
CentOS7编译安装php7.1的教程详解
Apr 18 PHP
php设计模式之适配器模式原理、用法及注意事项详解
Sep 24 PHP
将文件夹压缩成zip文件的php代码
Dec 14 #PHP
php入门教程 精简版
Dec 13 #PHP
php实现的仿阿里巴巴实现同类产品翻页
Dec 11 #PHP
Php Mssql操作简单封装支持存储过程
Dec 11 #PHP
php smarty模版引擎中变量操作符及使用方法
Dec 11 #PHP
phpmyadmin导入(import)文件限制的解决办法
Dec 11 #PHP
php smarty模版引擎中的缓存应用
Dec 11 #PHP
You might like
PHP图片裁剪函数(保持图像不变形)
2014/05/04 PHP
php使用str_replace实现输入框回车替换br的方法
2014/11/24 PHP
Mac OS下配置PHP+MySql环境
2015/02/25 PHP
php中memcache 基本操作实例
2015/05/17 PHP
PHP设计模式概论【概念、分类、原则等】
2020/05/01 PHP
纯CSS3实现质感细腻丝滑按钮
2021/03/09 HTML / CSS
通过设置CSS中的position属性来固定层的位置
2015/12/14 Javascript
基于Node.js的强大爬虫 能直接发布抓取的文章哦
2016/01/10 Javascript
学做Bootstrap的第一个页面
2016/05/15 HTML / CSS
js简单实现调整网页字体大小的方法
2016/07/23 Javascript
Js得到radiobuttonlist选中值的两种方法(推荐)
2016/08/25 Javascript
jQuery层次选择器用法示例
2016/09/09 Javascript
Javascript使用function创建类的两种方法(推荐)
2016/11/19 Javascript
js return返回多个值,通过对象的属性访问方法
2017/02/21 Javascript
利用Jasmine对Angular进行单元测试的方法详解
2017/06/12 Javascript
layui table 参数设置方法
2018/08/14 Javascript
分享5个小技巧让你写出更好的 JavaScript 条件语句
2018/10/20 Javascript
angular6开发steps步骤条组件
2019/07/04 Javascript
Antd的Table组件嵌套Table以及选择框联动操作
2020/10/24 Javascript
python益智游戏计算汉诺塔问题示例
2014/03/05 Python
python中pass语句用法实例分析
2015/04/30 Python
12步教你理解Python装饰器
2016/02/25 Python
Python设计模式之职责链模式原理与用法实例分析
2019/01/11 Python
详解Python循环作用域与闭包
2019/03/21 Python
python仿evething的文件搜索器实例代码
2019/05/13 Python
Python 异常的捕获、异常的传递与主动抛出异常操作示例
2019/09/23 Python
python3图片文件批量重命名处理
2019/10/31 Python
python函数局部变量、全局变量、递归知识点总结
2019/11/15 Python
用opencv给图片换背景色的示例代码
2020/07/08 Python
在 Python 中使用 MQTT的方法
2020/08/18 Python
Python hashlib和hmac模块使用方法解析
2020/12/08 Python
大学生工作推荐信范文
2013/12/02 职场文书
《中国的气候》教学反思
2014/02/23 职场文书
机械设备与数控技术专业求职信
2014/08/10 职场文书
幼儿园教师节感谢信
2015/01/23 职场文书
大学同学聚会感言
2015/07/30 职场文书