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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過給定的父ID將XML子節(jié)點存儲在PHP變量中?

如何通過給定的父ID將XML子節(jié)點存儲在PHP變量中?

PHP
慕碼人2483693 2023-08-06 15:36:05
<account VGS0035="VGS0035">        <realm>Smolderweb</realm>        <realmint>smolderweb-us</realmint>        <type>PvP</type>        <race>Undead</race>        <gender>Male</gender>        <class>Mage</class>        <faction>Horde</faction>        <level>60</level>        <description>(60% mount, green/blue gear)</description>        <price>210</price>        <stock>1</stock>        <id>VGS0035</id>        <screenshot>https://vanilla.games/wp-content/uploads/2019/08/wow-classic-mage.jpg</screenshot>    </account>    <account VGS0036="VGS0036">        <realm>Faerlina</realm>        <realmint>faerlina-us</realmint>        <type>PvP</type>        <race>Undead</race>        <gender>Male</gender>        <class>Mage</class>        <faction>Horde</faction>        <level>60</level>        <description>(100% mount, epic/blue gear, Tailoring 300, First Aid 225, MC+ONY+BWL attuned, 150 gold)</description>        <price>400</price>        <stock>1</stock>        <id>VGS0036</id>        <screenshot>https://i.imgur.com/cdeAdwe.jpg</screenshot>    </account>    <account VGS0037="VGS0037">        <realm>Faerlina</realm>        <realmint>faerlina-us</realmint>        <type>PvP</type>        <race>Undead</race>        <gender>Male</gender>        <class>Mage</class>        <faction>Horde</faction>        <level>60</level>        <description>(60% mount, green/blue/epic gear, 100 gold)</description>        <price>250</price>        <stock>1</stock>        <id>VGS0037</id>        <screenshot>https://vanilla.games/wp-content/uploads/2019/08/wow-classic-mage.jpg</screenshot>    </account>我將以下內(nèi)容封裝在 XML 標簽中。我有一個 PHP 頁面,我在其中傳遞變量 page?id=VGS0003 - 我想提取 PHP 變量中該節(jié)點的所有子元素以供使用。Example: $realm = $account->realm;$region = $account-region;$race = $account->race;我?guī)缀鯂L試了所有方法,但似乎沒有任何效果。無論我是否在循環(huán)中放置 if 語句,F(xiàn)oreach 都只返回最后一個節(jié)點。
查看完整描述

1 回答

?
慕森王

TA貢獻1777條經(jīng)驗 獲得超3個贊

一種選擇是使用 xpath"http://account[id='$id']"和您要查找的 id。


$elements = simplexml_load_string($xmlstr);

$id = "VGS0037";

$query = "http://account[id='$id']";

$account = $elements->xpath($query);

$accountRace = $account[0]->race;

echo $accountRace;

輸出


Undead

查看完整回答
反對 回復 2023-08-06
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號