0

我让网站完全正常工作并从 rss 提要返回信息,因为它返回网站链接我如何显示链接中的信息而不是将用户重定向回原始网站?

<?php

    $query = 'http://query.yahooapis.com/v1/public/yql?q=Select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fnestor.sunderland.ac.uk%2F~bf71wx%2FphpTest%2Fjquery.mobile-1.0.1%2520-%2520%25E8%25A4%2587%25E8%25A3%25BD%2Fjquery.mobile-1.0.1%2Fdemos%2Fdocs%2Frss%2FNews.xml%22%20&diagnostics=true';
    $xml = simplexml_load_file($query);
    //var_dump($xml);

    echo '<h2>World of Tank News</h2>';

    //iterate over query result set
    $results = $xml->results;
    foreach ($results->item as $r){
        echo $r->title . "<br />";
        echo "<a href=\"" . $r->link . "\">" . $r->link . "</a><br /><br />";
        echo 'Publish Date - ';

    }

?>
4

1 回答 1

0

使用 curl 从链接中读取信息并发布它,例如

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
$result = curl_exec($ch);
curl_close($ch);

没必要。您可以将此代码添加到您的程序中,例如

<?php

$query = 'http://query.yahooapis.com/v1/public/yql?q=Select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fnestor.sunderland.ac.uk%2F~bf71wx%2FphpTest%2Fjquery.mobile-1.0.1%2520-%2520%25E8%25A4%2587%25E8%25A3%25BD%2Fjquery.mobile-1.0.1%2Fdemos%2Fdocs%2Frss%2FNews.xml%22%20&diagnostics=true';
$xml = simplexml_load_file($query);
//var_dump($xml);

echo '<h2>World of Tank News</h2>';

//iterate over query result set
$results = $xml->results;
foreach ($results->item as $r){
echo $r->title . "<br />";
$ch = curl_init();

$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$r->link);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
//        echo "<a href=\"" . $r->link . "\">" . $r->link . "</a><br /><br />";
//        echo 'Publish Date - ';

}

?>
于 2012-04-22T23:53:46.823 回答