php 低版本兼容函数

Java代码   收藏代码
  1. <?php  
  2. if (! function_exists ( 'file_get_contents' )) {  
  3.     /** 
  4.      * 如果系统不存在file_get_contents函数则声明该函数 
  5.      * 
  6.      * @access  public 
  7.      * @param   string  $file 
  8.      * @return  mix 
  9.      */  
  10.     function file_get_contents($file) {  
  11.         if (($fp = @fopen ( $file, 'rb' )) === false) {  
  12.             return false;  
  13.         } else {  
  14.             $fsize = @filesize ( $file );  
  15.             if ($fsize) {  
  16.                 $contents = fread ( $fp, $fsize );  
  17.             } else {  
  18.                 $contents = '';  
  19.             }  
  20.             fclose ( $fp );  
  21.               
  22.             return $contents;  
  23.         }  
  24.     }  
  25. }  
  26.   
  27. if (! function_exists ( 'file_put_contents' )) {  
  28.     function file_put_contents($n, $d) {  
  29.         $f = @fopen ( $n, "w" );  
  30.         if (! $f) {  
  31.             return false;  
  32.         } else {  
  33.             fwrite ( $f, $d );  
  34.             fclose ( $f );  
  35.             return true;  
  36.         }  
  37.     }  
  38. }  
  39.   
  40. if (! function_exists ( 'floatval' )) {  
  41.     /** 
  42.      * 如果系统不存在 floatval 函数则声明该函数 
  43.      * 
  44.      * @access  public 
  45.      * @param   mix     $n 
  46.      * @return  float 
  47.      */  
  48.     function floatval($n) {  
  49.         return ( float ) $n;  
  50.     }  
  51. }  
  52. /*  
  53.  * $array = array ('fruit1' => 'apple', 'fruit2' => 'orange' ); =>fruit1=apple&fruit2=orange  
  54.  */  
  55. if(!function_exists('http_build_query'))  
  56. {  
  57.     function http_build_query($data, $prefix = null, $sep = '', $key = '')  
  58.     {  
  59.         $ret = array();  
  60.         foreach((array)$data as $k => $v)  
  61.         {  
  62.             $k = urlencode($k);  
  63.             if(is_int($k) && $prefix != null)  
  64.             {  
  65.                 $k = $prefix.$k;  
  66.             }  
  67.             if(!empty($key)) {  
  68.                 $k = $key."[".$k."]";  
  69.             }  
  70.             if(is_array($v) || is_object($v))  
  71.             {  
  72.                 array_push($ret,http_build_query($v,"",$sep,$k));  
  73.             }  
  74.             else  
  75.             {  
  76.                 array_push($ret,$k."=".urlencode($v));  
  77.             }  
  78.         }  
  79.         if(empty($sep))  
  80.         {  
  81.             $sep = ini_get("arg_separator.output");  
  82.         }  
  83.         return implode($sep, $ret);  
  84.     }  
  85. }  
  86.   
  87. if(!function_exists('image_type_to_extension'))  
  88. {  
  89.     function image_type_to_extension($type, $dot = true)  
  90.     {  
  91.         $e = array ( 1 => 'gif''jpeg''png''swf''psd''bmp' ,'tiff''tiff''jpc''jp2''jpf''jb2''swc''aiff''wbmp''xbm');  
  92.         $type = intval($type);  
  93.         if (!$type)  
  94.         {  
  95.             trigger_error( 'File Type is null...', E_USER_NOTICE );  
  96.             return null;  
  97.         }  
  98.         if(!isset($e[$type]))  
  99.         {  
  100.             trigger_error( 'Image type is wrong...', E_USER_NOTICE );  
  101.             return null;  
  102.         }  
  103.         return ($dot ? '.' : '') . $e[$type];  
  104.     }  
  105. }  
  106.   
  107. if(!function_exists('array_intersect_key'))  
  108. {  
  109.     function array_intersect_key($isec, $keys)  
  110.     {  
  111.         $argc = func_num_args();  
  112.         if ($argc > 2)  
  113.         {  
  114.             for ($i = 1; !empty($isec) && $i < $argc; $i++)  
  115.             {  
  116.                 $arr = func_get_arg($i);  
  117.                 foreach (array_keys($isec) as $key)  
  118.                 {  
  119.                     if (!isset($arr[$key]))  
  120.                     {  
  121.                         unset($isec[$key]);  
  122.                     }  
  123.                 }  
  124.             }  
  125.             return $isec;  
  126.         }  
  127.         else  
  128.         {  
  129.             $res = array();  
  130.             foreach (array_keys($isec) as $key)  
  131.             {  
  132.                 if (isset($keys[$key]))  
  133.                 {  
  134.                     $res[$key] = $isec[$key];  
  135.                 }  
  136.             }  
  137.             return $res;  
  138.         }  
  139.     }  
  140. }  
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值