如何获取带有图片的RSS Feed

时间:2019-01-15 11:30:30

标签: php rss

所以我一直在尝试显示新闻图片,但不会显示。我可以获取日期,标题和说明,因为它们是包含默认标签的字段,但是我也想获取新闻的图片。

但是我不知道为什么我无法获得图像。有什么办法吗?谢谢!

这是我的密码

1.index.php

<?php

include('rssclass.php');
$feedlist = new rss('http://www.skysports.com/rss/0,20514,11959,00.xml'); 

echo $feedlist->display(5,"PARSING XML GSM ARENA");

?>

<!DOCTYPE html>
<html>
<head>
	<title>UAS 2019</title>
</head>
<body>
		<style>
			body{
				background-image: url("wallpaper.jpg");
				font-family: georgia;
			}
			.kotak-berita{ /* Kotak Berita yang akan ditampilkan */
				margin:10 auto;
				width:800px;
				padding:20px;
			}

			.judul { /* Judul Header Berita */

				font-size:18px;
				font-weight:bold;
				text-align:center;
				background-color:#ef3114;
				color:#ffc9c1;
				padding:5px;
				border-radius:10px 10px 0 0;       
			}

			.link-feed { /* Link Feed */
				color:#3937bf;
				background: rgba(255,255,255,0.5);
				text-align:left;
				padding:5px;
				border:10px solid black;
			}
		</style>

		</footer>
	</body>
</html>

和我的班级2.rssclass.php

<?php

 class rss {
     var $feed;
  function rss($feed)
  {
    $this->feed = $feed;   
  }
  function parse()
  {
    $rss = simplexml_load_file($this->feed);
    $rss_split = array();
    foreach ($rss->channel->item as $item) {
      $title = (string) $item->title; // Judul
      $link   = (string) $item->link; // Link URL
      $description = (string) $item->description; // Deskripsi
      $pubDate = (string) $item->pubDate; //menampilkan tanggal
      
      $rss_split[] = '<div>'.$pubDate.'<br><br><a style="color: #3e0e47;font-weight:bold;">'.$title.'</a>'.$description.'<a href="'.$link.'" target="_blank" title="" >Read More....</a><hr>
      </div>';

    }

    return $rss_split;
  }

  function display($numrows,$head)
  {
    $rss_split = $this->parse();
    $i = 0;
    $rss_data = '<div class="kotak-berita">
    <div class="judul">'.$head.'</div> <div class="link-feed">';
    while ( $i < $numrows )
    {
      $rss_data .= $rss_split[$i];
      $i++;
    }
    $trim = str_replace('', '',$this->feed);
    $user = str_replace('&lang=en-us&format=rss_200','',$trim);    
    $rss_data.='</div></div>';

    return $rss_data;

  }

}

?>

0 个答案:

没有答案