Common function Collection _php Tutorial in PHP development process

Source: Internet
Author: User
1. Print array functions
Copy CodeThe code is as follows:
function _print ($array)
{
Echo ("


Echo ("
");
}

2. Intercept strings
Copy CodeThe code is as follows:
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. Loading files
Copy CodeThe code is as follows:
LoadFile
function LoadFile ($filepath)
{
$filecontent = "";
$fptr = fopen ($filepath, "R");
if ($fptr)
{
while ($content = Fgets ($fptr, 4096))
{
$filecontent. = $content;
}
Fclose ($FPTR);
}
return $filecontent;
}

4. Download the file
DownloadFile
Copy CodeThe code is as follows:
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. Array sorting
Copy CodeThe code is as follows:
/**
* @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 the use Array_multisort () function.
*
* Syssortarray ($Array, "Key1", "Sort_asc", "Sort_retular", "Key2" ...)
* @author Chunsheng Wang
* @param array $ArrayData the array to sort.
* @param string $KeyName 1 The first item to sort by.
* @param string $SortOrder 1 The order to sort by ("Sort_asc" | " Sort_desc ")
* @param string $SortType 1 the Sort type ("Sort_regular" | " Sort_numeric "|" Sort_string ")
* @return Array sorted array.
*/
function Syssortarray ($ArrayData, $KeyName 1, $SortOrder 1 = "Sort_asc", $SortType 1 = "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;
}

Source: http://www.cnblogs.com/xiaosuo/archive/2009/12/14/1594455.html

http://www.bkjia.com/PHPjc/320925.html www.bkjia.com true http://www.bkjia.com/PHPjc/320925.html techarticle 1. Print Array function Copy code code as follows: function _print ($array) {echo ("pre"), Print_r ($array); Echo ("/pre");} 2. The Intercept string copy code code is as follows: Func_chgtitle fun ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.