php 低版本兼容函数

<?php
if (! function_exists ( 'file_get_contents' )) {
	/**
	 * 如果系统不存在file_get_contents函数则声明该函数
	 *
	 * @access  public
	 * @param   string  $file
	 * @return  mix
	 */
	function file_get_contents($file) {
		if (($fp = @fopen ( $file, 'rb' )) === false) {
			return false;
		} else {
			$fsize = @filesize ( $file );
			if ($fsize) {
				$contents = fread ( $fp, $fsize );
			} else {
				$contents = '';
			}
			fclose ( $fp );
			
			return $contents;
		}
	}
}

if (! function_exists ( 'file_put_contents' )) {
	function file_put_contents($n, $d) {
		$f = @fopen ( $n, "w" );
		if (! $f) {
			return false;
		} else {
			fwrite ( $f, $d );
			fclose ( $f );
			return true;
		}
	}
}

if (! function_exists ( 'floatval' )) {
	/**
	 * 如果系统不存在 floatval 函数则声明该函数
	 *
	 * @access  public
	 * @param   mix     $n
	 * @return  float
	 */
	function floatval($n) {
		return ( float ) $n;
	}
}
/* 
 * $array = array ('fruit1' => 'apple', 'fruit2' => 'orange' ); =>fruit1=apple&fruit2=orange 
 */
if(!function_exists('http_build_query'))
{
    function http_build_query($data, $prefix = null, $sep = '', $key = '')
	{
        $ret = array();
		foreach((array)$data as $k => $v)
		{
			$k = urlencode($k);
			if(is_int($k) && $prefix != null)
			{
				$k = $prefix.$k;
			}
			if(!empty($key)) {
				$k = $key."[".$k."]";
			}
			if(is_array($v) || is_object($v))
			{
				array_push($ret,http_build_query($v,"",$sep,$k));
			}
			else
			{
				array_push($ret,$k."=".urlencode($v));
			}
		}
        if(empty($sep))
		{
            $sep = ini_get("arg_separator.output");
        }
        return implode($sep, $ret);
    }
}

if(!function_exists('image_type_to_extension'))
{
    function image_type_to_extension($type, $dot = true)
    {
        $e = array ( 1 => 'gif', 'jpeg', 'png', 'swf', 'psd', 'bmp' ,'tiff', 'tiff', 'jpc', 'jp2', 'jpf', 'jb2', 'swc', 'aiff', 'wbmp', 'xbm');
        $type = intval($type);
        if (!$type)
		{
            trigger_error( 'File Type is null...', E_USER_NOTICE );
            return null;
        }
        if(!isset($e[$type]))
		{
            trigger_error( 'Image type is wrong...', E_USER_NOTICE );
            return null;
        }
        return ($dot ? '.' : '') . $e[$type];
    }
}

if(!function_exists('array_intersect_key'))
{
	function array_intersect_key($isec, $keys)
	{
		$argc = func_num_args();
		if ($argc > 2)
		{
			for ($i = 1; !empty($isec) && $i < $argc; $i++)
			{
				$arr = func_get_arg($i);
				foreach (array_keys($isec) as $key)
				{
					if (!isset($arr[$key]))
					{
						unset($isec[$key]);
					}
				}
			}
			return $isec;
		}
		else
		{
			$res = array();
			foreach (array_keys($isec) as $key)
			{
				if (isset($keys[$key]))
				{
					$res[$key] = $isec[$key];
				}
			}
			return $res;
		}
	}
}
 

你可能感兴趣的:(PHP,json,F#,Access,FP)