** 获取远程文件内容 @param $url 文件http地址 * function fopen_url($url) { if (function_exists(& 39;file_get_contents& 39;)) { $file_content = @file_get_contents($url); } elseif (ini_get(& 39;allow_url_fopen& 39;) && ($file = @fopen($url, & 39;rb& 39;))){ $i = 0; while (!feof($
/** 
    获取远程文件内容 
    @param $url 文件http地址 
*/ 
function fopen_url($url) 
{ 
    if (function_exists('file_get_contents')) { 
        $file_content = @file_get_contents($url); 
    } elseif (ini_get('allow_url_fopen') && ($file = @fopen($url, 'rb'))){ 
        $i = 0; 
        while (!feof($file) && $i++ < 1000) { 
            $file_content .= strtolower(fread($file, 4096)); 
        } 
        fclose($file); 
    } elseif (function_exists('curl_init')) { 
        $curl_handle = curl_init(); 
        curl_setopt($curl_handle, CURLOPT_URL, $url); 
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2); 
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1); 
        curl_setopt($curl_handle, CURLOPT_FAILONERROR,1); 
        curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Trackback Spam Check'); 
        $file_content = curl_exec($curl_handle); 
        curl_close($curl_handle); 
    } else { 
        $file_content = ''; 
    } 
    return $file_content; 
}


来自:PHP100

关键字标签:

上一篇:php中文汉字截取函数
下一篇:php验证用户名是否以字母开头与验证密码