相对网址不适用于getheaders [英] relative url not working for getheaders

查看:88
本文介绍了相对网址不适用于getheaders的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此脚本,它对于img src标签中的绝对URL正常工作,但是如果img src标签具有相对URL,则它将失败并给出错误

here is this script which works just fine for absolute url in img src tag but if img src tag is having relative url it fails and give error

Warning: get_headers() [function.get-headers]:此功能只能用于 在第一个链接中img src是相对URL,但在第二个链接中img src是绝对URL,它给出了理想的结果,但是我希望我的脚本在两种情况下都能正常工作吗?

Warning: get_headers() [function.get-headers]: This function may only be used against URLs in in first link img src is relative url but in second link img src is absolute url and it gives perfect result but i want my script to work in both cases any idea??

<?php
$websitelink = 'http://img172.imagevenue.com/img.php?image=90465_Gwen3_122_17lo.jpg';

//  $websitelink='http://www.santabanta.com/bollywood/76432/whoa-after-200-crore-now-dhoom-3-races-for-rs-300-crore-mark/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $websitelink);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resulty = curl_exec($ch);
$doc = new DOMDocument();
@$doc->loadHTML($resulty);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
    $data = get_headers($tag->getAttribute('src'), 1);
    if ((intval($data["Content-Length"])) >= 30720) {
        $op7 = '' . $tag->getAttribute('src') . '';
        echo $op7 . '</br>';
    }
}

推荐答案

函数get_headers实际上会执行一个HTTP GET请求,因此它需要一个完全限定的地址,并且在以下情况下无法工作您只指定相对网址.

The function get_headers will actually perform a HTTP GET request, therefore it needs a fully qualified address, and cannot work if you specify only a relative URL.

您将必须推断要尝试加载的图像的完整地址.

You will have to infer what's the complete address to the image you're trying to load.

这篇关于相对网址不适用于getheaders的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆