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

1.打印数组函数
<div class="codetitle"><a style="CURSOR: pointer" data="72559" class="copybut" id="copybut72559" onclick="doCopy('code72559')"> 代码如下:

<div class="codebody" id="code72559">
function _print($array)
{
echo ("
"); 
print_r($array);
echo ("
");
}

2.截取字串
<div class="codetitle"><a style="CURSOR: pointer" data="64273" class="copybut" id="copybut64273" onclick="doCopy('code64273')"> 代码如下:
<div class="codebody" id="code64273">
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,2);
$i++;
}
else
$tmpstr .= substr($str,1);
}
return $tmpstr."";
}
else
{
return $str;
}
}

3.加载文件
<div class="codetitle"><a style="CURSOR: pointer" data="42247" class="copybut" id="copybut42247" onclick="doCopy('code42247')"> 代码如下:
<div class="codebody" id="code42247">
loadFile
function loadFile($filepath)
{
$filecontent = "";
$fptr = fopen($filepath,"r");
if ($fptr)
{
while ($content = fgets($fptr,4096))
{
$filecontent .= $content;
}
fclose($fptr);
}
return $filecontent;
}

4.下载文件
downloadFile
<div class="codetitle"><a style="CURSOR: pointer" data="81768" class="copybut" id="copybut81768" onclick="doCopy('code81768')"> 代码如下:
<div class="codebody" id="code81768">
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.数组排序
<div class="codetitle"><a style="CURSOR: pointer" data="63205" class="copybut" id="copybut63205" onclick="doCopy('code63205')"> 代码如下:<div class="codebody" id="code63205">
/*
@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;
}

来源:<A href="http://www.cnblogs.com/xiaosuo/archive/2009/12/14/1594455.html"&gt;http://www.cnblogs.com/xiaosuo/archive/2009/12/14/1594455.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

PHP常用函数

相关推荐


如何选择合适的 C++ Web 开发框架?
利用 C++ 框架构建高并发 Web 应用的策略
用 C++ 框架开发跨平台图形应用程序
golang框架中安全编码实践的最佳指南是什么?
golang框架与其他语言框架在设计理念上的区别有哪些?
C++ 图形框架与其他语言框架的比较
C++ 框架与其他 Web 开发框架的对比分析
使用 C++ 框架构建大型项目最佳实践
C++ 框架如何提高大型项目开发效率
C++ 框架中依赖注入的持续集成与部署工具
如何与社区协作和贡献到自定义 Golang 框架?
C++ 框架在大型项目中如何实现模块化开发
使用 C++ 框架开发跨平台 Web 应用
C++ 框架在大型项目中的优缺点
golang框架在性能上的优势体现在哪些方面?
C++ 框架在嵌入式系统内存优化中的优势
golang框架在人工智能与机器学习中的作用
如何扩展 Golang 框架以支持特定功能?
如何利用 Go Modules 和依赖项管理来自定义 Golang 框架?
Golang 框架中的性能优化技巧