一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php4如何获取远程文件大小类

时间:2022-06-24 18:32:41 编辑:袖梨 来源:一聚教程网

 /*
 
 */

 代码如下 复制代码

if(!function_exists('get_headers'))
{
    function get_headers($url,$format=0)
    {
        $url=parse_url($url);
        $end = " ";
        $fp = fsockopen($url['host'], (empty($url['port'])?80:$url['port']), $errno, $errstr, 30);
        if ($fp)
        {
            $out  = "get / http/1.1 ";
            $out .= "host: ".$url['host']." ";
            $out .= "connection: close ";
            $var  = '';
            fwrite($fp, $out);
            while (!feof($fp))
            {
                $var.=fgets($fp, 1280);
                if(strpos($var,$end))
                    break;
            }
            fclose($fp);

            $var=preg_replace("/ .*$/",'',$var);
            $var=explode(" ",$var);
            if($format)
            {
                foreach($var as $i)
                {
                    if(preg_match('/^([a-za-z -]+): +(.*)$/',$i,$parts))
                        $v[$parts[1]]=$parts[2];
                }
                return $v;
            }
            else
                return $var;
        }
    }
}

热门栏目