我已經設法使用PHP創建XML文檔。我現在想用PHP來循環訪問xml文檔並適當地顯示它。這是我已經有的代碼,但似乎沒有工作。使用PHP處理XML
PHP循環
<?php
$rss2 = simplexml_load_file('food.xml');
print "<h3>XML document processed with PHP</h3>";
foreach ($rss2->xml->item as $item){
print "Title: ". $item->name."<br>";
print "Link: <a href=".$item->link.">".$item->link."</a><br>";
print "Description: ". $item->description."<br>";
print "<hr />";
}
?>
XML文檔
<?xml version="1.0"?>
<xml>
<item>
<name>Food home page</name>
<link>http://www.food.com/</link>
<description>home cooking inspiration</description>
</item>
<item>
<name>Popular recipes</name>
<link>http://www.food.com/recipes-popular</link>
<description>Popular home food recipes</description>
</item>
<item>
<name>Pulled pork</name>
<link>http://www.food.com/recipe/pulled-pork-crock-pot-131018</link>
<description>Crock pot pulled pork recipe</description>
</item>
</xml>
任何人的幫助將不勝感激 感謝
RSS的文檔元素應該是「rss」而不是「xml」。 * BTW * – ThW 2014-11-22 12:02:46