我有以下 php 代码:
$xml=simplexml_load_file("http://openclipart.org/api/search/?query=dog&page=1");
echo "<ul>";
foreach ($xml->channel->item as $clipinfo):
$title=$clipinfo->title;
$full=$clipinfo->enclosure['url'];
$thumb=$clipartinfo->children('media', true)->thumbnail['url'];
echo "<div style=\"width:160px;height:120px;float:left;margin:5px;margin-top:10px;\">
<a href=\"{$full}\" target='_blank' class=\"thumbnail\">
<img alt=\"{$title}\" style=\"width: 160px; height: 120px;\" src=\"{$thumb}\">
</a>
</div>";
endforeach;
这是由以下 XML 文件提供的:
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>OpenClipart.org</title>
<atom:link rel="self" href="http://openclipart.org/api/search/?query=dog&page=1" type="application/rss+xml"/>
<link>http://openclipart.org</link>
<description>Download, Sample, Cut-up, Share.</description>
<language>en-US</language>
<image>
<url>http://openclipart.org/assets/images/images/logo-no-text.jpg</url>
<link>http://openclipart.org</link>
<title>OpenClipart.org</title>
<height>93</height>
<width>114</width>
</image>
<item>
<title>walking dog</title>
<link>http://openclipart.org/detail/720/walking-dog-by-johnny_automatic</link>
<pubDate>Tue, 17 Oct 2006 21:23:37 -0400</pubDate>
<dc:creator>johnny_automatic</dc:creator>
<description>cartoon of a girl walking a dog from http://www.usda.gov/cnpp/KidsPyra/National Agricultural Library, Agricultural Research Service, U. S. Department of Agriculture</description>
<enclosure url="http://openclipart.org/people/johnny_automatic/johnny_automatic_walking_dog.svg" type="image/svg+xml" length="99841"/>
<guid>http://openclipart.org/detail/720/walking-dog-by-johnny_automatic</guid>
<cc:license>http://creativecommons.org/licenses/publicdomain</cc:license>
<media:thumbnail url="http://openclipart.org/image/90px/svg_to_png/720/johnny_automatic_walking_dog.png"/>
</item>
<media:thumbnail>
为什么我的 foreach 语句无法获取url 属性?(我已经阅读了用于解析带有标记名称中的冒号的 XML 的 PHP 库?)这是一个不同的问题。