<?php
# INSTANTIATE CURL.
$curl = curl_init();
# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL, "http://www.dpm.uk.com/feeds/rss/product-syndication.ashx?pgid=6&feed=opt1");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
# GRAB THE XML FILE.
$xml = curl_exec($curl);
curl_close($curl);
# SET UP XML OBJECT.
$xmlObj = simplexml_load_string( $xml );
$tempCounter = 0;
foreach ( $xmlObj->item as $item )
{
# DISPLAY ONLY 10 ITEMS.
if ( $tempCounter < 20 )
{
echo "
<div class=\"feed-item\">
Title: {$item -> title}
Year: {$item -> Year}
Colours: {$item -> Colours}
Size: {$item -> Size}
Available: {$item -> Available}
Image: {$item -> Images}
<br>
</div>
";
}
$tempCounter += 1;
}
?>
答案 0 :(得分:0)
<?php
error_reporting(E_ALL);
$data = file_get_contents("http://www.dpm.uk.com/feeds/rss/product-syndication.ashx?pgid=6&feed=opt1");
$xml = new SimpleXMLElement($data);
$counter = 0;
foreach ($xml->item as $item) {
if ($counter < 20){
echo "<div class=\"feed-item\">
Title: " . $item->title . ", " . "
Year: " . $item->Year . "
<br></div>";
}
}
?>
测试它的工作原理
答案 1 :(得分:0)
$img = $item->Images->img[0]->attributes();
echo "
<div class=\"feed-item\">
Title: {$item->title}
Year: {$item->Year}
Colours: {$item->Colours}
Size: {$item->Size}
Available: {$item->Available}
Image: {$img['src']}
<br>
</div>
";
<强>更新强>
显示图像:
echo "Image: <img src=\"{$img['src']}\" width=\"{$img['width']}\" height=\"{$img['height']}\" />";
要显示所有图像:
foreach ($item->Images as $img) {
$img = $img->attributes();
echo "Image: <img src=\"{$img['src']}\" width=\"{$img['width']}\" height=\"{$img['height']}\" />";
}