douka19950505 2014-01-27 07:16
浏览 382

如何从RSS网址获取完整内容?

I’m developing an RSS fetcher API which can fetch the full RSS content from RSS URL. I have searched a lot but I am unable to make it work. Now my API gets only short content (description) from RSS feed URL.

The code used by me:

 $rss = fetch_feed($entry->rss_link);
    $number_of_post=2;
    $iCount=0;
    foreach ($rss->get_items() as $item)
    {
        $content= $item->get_description();
        if($entry->remove_link){
           $content=strip_tags($content, '<p><div><i><b><u><img>');
        }
        $iCount++;
        $sfp_page = array(
            'post_title' => $item->get_title(),
            'post_status' => 'publish',
            'post_content' =>$content,
            'post_type' => 'sfp_forum',
            'post_author' => $entry->author_id,
            'post_date' => current_time('mysql')
        );
        $rss_id = wp_insert_post($sfp_page);

    }

$content doesn’t have the full content.

Any suggestions?

  • 写回答

1条回答 默认 最新

  • duanlu9816 2014-01-27 07:21
    关注

    You probably need to do something like the following because you are overwriting your $content on each iteration so you only get the last item.

    $rss = fetch_feed($entry->rss_link);
    $number_of_post=2;
    $iCount=0;
    $content = array();
    foreach ($rss->get_items() as $item){
        $content[$iCount] = $item->get_description();
        if($entry->remove_link){
           $content[$iCount] = strip_tags($content[$iCount], '<p><div><i><b><u><img>');
        }
        $iCount++;
    }
    var_dump($content);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?