-2
您好先生我想從RSS Feed使用捲曲方法獲取圖像路徑...我試過這個代碼,但它不工作...請幫助!!!!使用捲曲方法從RSS提要獲取圖像路徑
<?php
$feed = "http://feeds.bbci.co.uk/news/uk/rss.xml";
// Use cURL to fetch text
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feed);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
$rss = curl_exec($ch);
curl_close($ch);
// Manipulate string into object
$rss = simplexml_load_string($rss);
$siteTitle = $rss->channel->title;
echo "<h1>".$siteTitle."</h1>";
echo "<hr />";
$cnt = count($rss->channel->item);
for($i=0; $i<10; $i++)
{
$images = $rss->channel->thumbnail->xpath('url');
echo "Image Path : ".$image;
echo "</br>";
}
?>
我累了,但又不工作 – user3193751
我寫的只是返回SimpleXMLElement。你需要像(字符串)$ rss-> channel-> image-> url一樣使用它。但是在你的代碼中有更多的錯誤。 $ images/$ image typo,undefined $ useragent variable ... –