您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP函数收藏

2024/4/15 6:31:05发布26次查看
此中将收藏我在工作中用到的一些php函数。有自己写的,也会有网上收集的。此文不断更新中
1.打印数组函数
function  _print( $array )
{
     echo  (
);
         print_r ( $array );
     echo  (
);
} 2.截取字串
func_chgtitle
function func_chgtitle($str,$len) 

    if(strlen($str)>$len)
    {
        $tmpstr = ;
        $strlen = $len;
        for($i = 0; $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 
* @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               {
                 $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 ;
    }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product