0

URL を「計算」してリダイレクトする必要があります。次のコードがあります。

<?php

//Basic HTML parsing with PHP
    include("simple_html_dom.php");

    $htmlCode = file_get_html('http://example.net/example.html');

    foreach($htmlCode->find('div[class=frontPageImage]') as $element) {

        foreach($element->find('img') as $imagee)
            $imgurl = $imagee->src;
    }

header("'Location:".$imgurl."'");

?>

最初に $imgurl で URL を取得し、後でその URL にリダイレクトします...しかし、機能しません..

アイデアや提案はありますか?ありがとう

4

1 に答える 1

3
header("'Location:".$imgurl."'");

おそらく次のようになります。

header("Location: " . $imgurl);

'HTTP ヘッダーは次のようになるため、一重引用符を削除しました。

'Location: http://site.com/image.jpg'

一重引用符のため無効です。

また、ループして多くの画像 URL を見つけていますが、最後の URL にリダイレクトするだけです。

于 2012-07-23T22:17:30.533 に答える