发点我现在常用的一些函数。
不足之处,敬请指正。//用于替代file_get_contents 为什么要替代,请google
function curl_get_contents($url)

   $ch = curl_init() or die (curl_error());   
   curl_setopt($ch,CURLOPT_URL,$url);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   $result = curl_exec($ch) or die (curl_error());
   curl_close($ch);
   return $result;  
}
<?php
/**
 * 返回给指定的日期添加天数后的日期
 *
 * @param string $date 被添加的日期
 * @param int $addDay 添加的天数
 * @return string
 */
function dateAdd($date, $addDay){
   $parts = explode(' ', $date);
   $date = $parts[0];
   $time = $parts[1];
   $ymd = explode('-', $date);
   $hms = explode(':', $time);
   $year = $ymd[0];
   $month = $ymd[1];
   $day = $ymd[2];
   $hour = $hms[0];
   $minute = $hms[1];
   $second = $hms[2];
   $day = $day+$addDay;  
   if($month=='1' || $month=='3' || $month=='5' || $month=='7' || $month=='8' || $month=='10' || $month=='12'){
      if($day>31){
         $day = $day - 31;
         $month++;
      }
   }
   if($month=='4' || $month=='6' || $month=='9' || $month=='11'){
      if($day>30){
         $day = $day - 30;
         $month++;
      }
   }
   if($month=='2'){
      if(checkRun($year)){
          //Feb has 29 days in leap year
         if($day>29){
            $day = $day - 29;
            $month++;
         }
      }
      else{
         if($day>28){
            $day = $day - 28;
            $month++;
         }
      }
   }
   if($month==13){
      $month = 1;
      $year++;
   }
   if(strlen($month)==1){$month = "0".$month;}
   if(strlen($day)==1){$day = "0".$day;}
   return $year . "-" . $month . "-" . $day;
}/**
 * 验证是否是润年
 *
 * @param int $year 年份
 * @return boolean 如果是则返回True,否则返回False
 */
function checkRun($year){
   if($year%4==0 && ($year%100!=0 || $year%400==0) )
      return true;
   else
      return false;
}/**
 * 将时间转化成秒
 * @param string $time
 */
function time_to_second($time) {
if (is_time($time)) {
$array_time = explode(':', $time);
return $array_time[0]*3600+$array_time[1]*60+$array_time[2];
} else {
return 0;
}
}/**
 * 将时间转化为unix时间戳
 *
 * @param string $date
 * @return int 如果转化成功则返回unix时间戳,否则返回-1
 */
function format_date_to_unix($date){
$date = trim($date);
$regexp = '^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})( ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}))?$';
if(ereg($regexp,$date,$regs)){
return mktime($regs[5],$regs[6],$regs[7],$regs[2],$regs[3],$regs[1]);
}else{
return -1;
}
}/**
 * Calculation of the time the auction closes
 * @param int $begin unix timestamp
 * @param int $end unix timestamp
 * @return string The time the auction closes
 */
function date_between($begin, $end = 0, $between = FALSE)
{
if ($end === 0) $end = time();
if ($between === FALSE) $between = $begin - $end;
if($between < 0) return '';
if ($between < 60)
{
return $between.'秒';
}
else
{
$second  = $between % 60;
$between = $between / 60;
if ($between < 60)
{
return (int)$between."分".$second."秒";
}
else if($between === 60)
{
return "1小时";
}
else
{
$minute = $between % 60;
$between = ($between - $minute) / 60;
if ($between < 24)
{
$string = (int)$between."小时";
if ($minute > 0)
{
$string .= $minute."分";
}
return $string;
}
else if($between === 24)
{
return "1天";
}
else
{
$hour  = $between % 24;
$between = $between - $hour;
$day  = $between / 24;
$string = (int)$day."天";
if ($hour > 0)
{
$string .= $hour."小时";
}
if ($minute > 0)
{
$string .= $minute."分";
}
return $string;
}
}
}
}
字符串处理//base_encode 和base_decode 用于加密,方便汉字传参时用,亦有加密的效果。
function base_encode($str)
{
        $src  = array("/","+","=");
        $dist = array("-a","-b","-c");
        $old  = base64_encode($str);
        $new  = str_replace($src,$dist,$old);
        return $new;
}function base_decode($str)
{
        $src = array("-a","-b","-c");
        $dist  = array("/","+","=");
        $old  = str_replace($src,$dist,$str);
        $new = base64_decode($old);
        return $new;
}//取摘要,得到第一张图,和指定长度内的文字。
function get_brief($newContent,$length = 100)
{
$pattern = "/<img[^>]*src\=('|\")(([^>]*)(jpg|gif|png|bmp|jpeg))\\1/i";   //获取所有图片标签的全部信
preg_match_all($pattern, $newContent, $matches);     $str_out = "";
if( sizeof( $matches[2] ))
{
       $str_out = "<img width = '120' src = '".$matches[2][0]."'/>";
}


$content = strip_tags($newContent);

if(strlen($content)>$length)
{
$str_out .= sub_string_utf8($content,0,$length);
}
else 
{
$str_out .= $content;
}

return $str_out;
}function sub_string_utf8($str, $start, $lenth)
{
    $len = strlen($str);
    $r = array ();
    $n = 0;
    $m = 0;
    for ($i = 0; $i < $len; $i++)
    {
        $x = substr($str, $i, 1);
        $a = base_convert(ord($x), 10, 2);
        $a = substr('00000000' . $a, -8);
        if ($n < $start)
        {
            if (substr($a, 0, 1) == 0)
            {
            }
            elseif (substr($a, 0, 3) == 110)
            {
                $i += 1;
            }
            elseif (substr($a, 0, 4) == 1110)
            {
                $i += 2;
            }
            $n++;
        }
        else
        {
            if (substr($a, 0, 1) == 0)
            {
                $r[] = substr($str, $i, 1);
            }
            elseif (substr($a, 0, 3) == 110)
            {
                $r[] = substr($str, $i, 2);
                $i += 1;
            }
            elseif (substr($a, 0, 4) == 1110)
            {
                $r[] = substr($str, $i, 3);
                $i += 2;
            }
            else
            {
                $r[] = '';
            }
            if (++ $m >= $lenth)
            {
                break;
            }
        }
    }
    return join("", $r);
} // End subString_UTF8
//还是取文章摘要。。
function Generate_Brief($text,$Briefing_Length = '100'){ 
        
if(mb_strlen($text) <= $Briefing_Length ) { echo "here"; return $text;} 

$Foremost = mb_substr($text, 0, $Briefing_Length); 

$re = "<(\/?) 
(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|TABLE|TR|TD|TH|INPUT|SELECT|TEXTAREA|OBJECT|A|UL|OL|LI| 
BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|SPAN)[^>]*(>?)"; 
$Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|BR/i"; 
$Stack = array(); $posStack = array(); 
mb_ereg_search_init($Foremost, $re, 'i'); 
while($pos = mb_ereg_search_pos()){ 
$match = mb_ereg_search_getregs(); 
/* [Child-matching Formulation]: 
$matche[1] : A "/" charactor indicating whether current "<...>" Friction is 
Closing Part 
$matche[2] : Element Name. 
$matche[3] : Right > of a "<...>" Friction 
*/ 
if($match[1]==""){ 
$Elem = $match[2]; 
if(mb_eregi($Single, $Elem) && $match[3] !=""){ 
continue; 

array_push($Stack, mb_strtoupper($Elem)); 
array_push($posStack, $pos[0]); 
}else{ 
$StackTop = $Stack[count($Stack)-1]; 
$End = mb_strtoupper($match[2]); 
    if(strcasecmp($StackTop,$End)==0){ 
array_pop($Stack); 
array_pop($posStack); 
if($match[3] ==""){ 
$Foremost = $Foremost.">"; 

       } 


$cutpos = array_shift($posStack) - 1; 
$Foremost = mb_substr($Foremost,0,$cutpos,"UTF-8"); 

return $Foremost; 
};
/**
 * 过滤特殊字符
 *
 * @param string $string 待过滤的字符
 * @param boolean $is_trim 是否去掉字符串两边的空格 TRUE为去掉,FALSE为不去掉,默认值为FALSE
 * @return string
 */
function str_filter($string, $is_trim = false)
{
if (trim($string) == "") return "";
if (!get_magic_quotes_gpc())
{
$string = addslashes($string);
}
$string = htmlspecialchars($string); 
$string = strip_tags($string);
return $is_trim ? trim($string) : $string;
}function strip_html($string)
{
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript 4B+1ZsmMd  
          "'<[/!]*?[^<>]*?>'si",       // 去掉 HTML 标记
          "'([rn])[s]+'",           // 去掉空白字符
          "'&(quot|#34);'i",           // 替换 HTML 实体
          "'&(amp|#38);'i",
          "'&(lt|#60);'i",
          "'&(gt|#62);'i",
          "'&(nbsp|#160);'i",
          "'&(iexcl|#161);'i",
          "'&(cent|#162);'i",
          "'&(pound|#163);'i",
          "'&(copy|#169);'i",
          "'&#(d+);'e");
$replace = array(
        "",
            "",
            "\1",
            "\"",
            "&",
            "<",
            ">",
            " ",
            chr(161),
            chr(162),
            chr(163),
            chr(169),
            "chr(\1)");
return preg_replace($search, $replace, $string); 
}function str_nl($string) {
return nl2br(str_replace(' ', '&nbsp;', $string));
}