dousong2023 2016-09-23 21:10
浏览 36

为什么我的RSS feed file_get_contents不起作用?

I'm trying to set up a live feed from a blog, but the contents are not displays. Any ideas? The blog is based in WP, I've set a contents curl below to a php file. The php file contains another curl to the physical blog feed.

<?php

try{

            // Get RSS feed
            $blog_feed = @file_get_contents_curl('http://www.coordsport.com/csblogfeed.php');

if ($blog_feed){

            // Convert to traversable XML object
            $blog_posts = new SimpleXMLElement($blog_feed);

            // Set limits and counter
            $list_count = 5;
            $current_item = 0;

            // Loop through each feed item
            foreach ($blog_posts->channel->item as $blog_post)
            {
                // Increment counter and check count
                if (++$current_item > $list_count) break;

                // Force data type for description
                $post_description = (string)$blog_post->description;

                $desc_xml = new SimpleXMLElement('<div>' . $post_description . '</div>');

                // Reset thumbnail
                $thumbnail_src = '';

                if (@$desc_xml->img[0])
                {
                    $thumbnail_src = (string) $desc_xml->img[0]->attributes()->src;
                }

}
else
{
echo 'Error Loading Feed';
}

    }
    catch(Exception $e)
    {
            echo 'Error Loading Feed.<br /><br /><div style="font-size:75%;color:#ccc;">' . htmlspecialchars($e) . '</div>';
    }

?>

The file_get_contents_curl csblogfeed.php contains, the blog is working fine and displays correctly in the below URL.

<?php

echo file_get_contents('http://www.coordsport.com/blog/feed/');

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)