0

这是这个脚本,它适用于 img src 标记中的绝对 url,但如果 img src 标记具有相对 url,它会失败并给出错误

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

<?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>';
    }
}
4

1 回答 1

2

该函数get_headers实际上会执行一个HTTP GET请求,因此它需要一个完全限定的地址,如果您只指定一个相对 URL,它就无法工作。

您将不得不推断您尝试加载的图像的完整地址是什么。

于 2013-12-31T19:46:03.697 回答