第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

循環(huán)遍歷 xml 數(shù)據(jù)。只得到第一個(gè)結(jié)果

循環(huán)遍歷 xml 數(shù)據(jù)。只得到第一個(gè)結(jié)果

PHP
RISEBY 2023-08-19 10:51:55
我不明白為什么這沒(méi)有在所有孩子中循環(huán)。它只顯示第一個(gè)孩子/結(jié)果。任何幫助,將不勝感激 :)PHP for 循環(huán)代碼:$xml = simplexml_load_file('data.xml') or die('Failed to create an object');  foreach($xml->children() as $xml_node) {              echo $xml_node->item->title . ", ";         echo $xml_node->item->description . ", ";     }數(shù)據(jù).xml<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0"><channel><title>Reviews</title><description>5 Star Reviews</description><item><title>Review 1 on Google</title><description>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis</description><pubDate>Wed, 08 Jul 2020</pubDate></item><item><title>Review 2 on Google</title><description>Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</description><pubDate>Tue, 07 Jul 2020</pubDate></item><item><title>Review 3 on Google</title><description>Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, </description><pubDate>Fri, 26 Jun 2020</pubDate></item><item><title>Review 4 on Google</title><description>Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio </description><pubDate>Fri, 26 Jun 2020</pubDate></item></channel></rss>
查看完整描述

1 回答

?
瀟湘沐

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊

您僅獲得該rss元素的第一個(gè)子元素,即channel的唯一子元素rss。這告訴它只循環(huán)一次。您需要指定您希望其子元素channel是多個(gè)item元素。


請(qǐng)嘗試以下方法:


$xml = simplexml_load_file('data.xml') or die('Failed to create an object');

  foreach($xml->channel->children() as $xml_node) {          

    echo $xml_node->title . ", ";     

    echo $xml_node->description . ", ";     

}

item通過(guò)此更改,您可以訪問(wèn):title和的直接子元素description。


查看完整回答
反對(duì) 回復(fù) 2023-08-19
  • 1 回答
  • 0 關(guān)注
  • 161 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)