dongtaotao19830418 2012-04-22 23:51
浏览 20

如何在不离开网站的情况下显示链接中的信息? PHP

I got the site fully working and returning the information from the rss feed since the it return with website link how can i display the information from the link instead of redirect the user back to the original site?

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

    }

?>
  • 写回答

1条回答 默认 最新

  • drnrxv9383 2012-04-22 23:53
    关注

    use curl to read the info from link and publish it e.g.

    $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);
    

    no need. you can add this code in your prog e.g.

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭