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

2015-01-24信息快讯网
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在页面中调用fckeditor编辑器的方法
rephactor 优秀的PHP的重构工具
php错误提示failed to open stream: HTTP request failed!的完美解决方法
php smarty 二级分类代码和模版循环例子
PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数的小问题
php file_put_contents()功能函数(集成了fopen、fwrite、fclose)
php异常:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE eval()'d code error
Views rows style模板重写代码
php中在PDO中使用事务(Transaction)
php 截取字符串并以零补齐str_pad() 函数
用PHP的超级变量$_POST获取HTML表单(HTML Form) 数据
用PHP的超级变量$_GET获取HTML表单(Form) 数据
PHP的substr_replace将指定两位置之间的字符替换为*号
php HandlerSocket的使用
fleaphp rolesNameField bug解决方法
在smarty模板中使用PHP函数的方法
PHP学习之输出字符串(echo,print,printf,print_r和var_dump)
PHP stream_context_create()作用和用法分析
php csv操作类代码
将文件夹压缩成zip文件的php代码
php smarty模版引擎中变量操作符及使用方法
phpmyadmin导入(import)文件限制的解决办法
php smarty模版引擎中的缓存应用
Php 构造函数construct的前下划线是双的_
php smarty模版引擎中的缓存应用
php session_start()关于Cannot send session cache limiter - headers already sent错误解决方法
php google或baidu分页代码
PHP CKEditor 上传图片实现代码
phpmailer 中文使用说明(简易版)
Wordpress php 分页代码
php foreach、while性能比较
使用zend studio for eclipse不能激活代码提示功能的解决办法
PHP parse_url 一个好用的函数
php面向对象全攻略 (十一)__toString()用法 克隆对象 __call处理调用错误
PHP 分页类(模仿google)-面试题目解答
PHP 源代码分析 Zend HashTable详解第1/3页
php str_pad 函数用法简介
php strlen mb_strlen计算中英文混排字符串长度
php 无限级 SelectTree 类
©2014-2024 dbsqp.com