我似乎無法弄清楚這一點。我正在嘗試從xml文件加載數據,具體取決於url參數的值。我有一個屬性設置在我的XML中,但似乎無法弄清楚如何去做這件事。我已經看了幾個獲取屬性的例子,所以我不確定我錯在哪裏,因爲我沒有遇到使用url參數來確定應該獲取哪些數據的例子。這是我到目前爲止。從URL參數獲取基於XML數據
我的xml
文件的示例。在這個文件中會有更多的piercing
的記錄。
<piercings>
<piercing id="antieyebrow">
<title>Anti-Eyebrow</title>
<names>Anti-Eyebrow, Teardrop</names>
<gauge>16</gauge>
<healing>6 - 8</healing>
<risk>Rejection/Migration, Scarring</risk>
<description>The anti-eyebrow piercing is located on the upper side of the cheek bone right below the orbital socket of the eye. This piercing is most commonly pierced using a 16 gauge curved barbell or custom bent jewelry. This piercing may also be referred to as a teardrop piercing.</description>
<aftercare>It is recommended with this piercing to clean twice a day using saline solution or antibacterial soap. Do not overclean. Irritation from overcleaning can result in migration of the piercing.
</aftercare>
<avoid>Using rubbing alchohol as a cleaner. Changing the jewelry for atleast 3 weeks although recommended to wait until the piercing is fully healed. Pools/hot tubs especially those with chemical cleaners in them. Swimming holes, creeks, rivers, etc. due to bacterial exposure risk.</avoid>
<img>http://example.com/img/display/stock/antieyebrow_default.jpg</img>
<additionalimgs>
<additionalimg>http://example.com/img/thumb/stock/antieyebrow_1.jpg</additionalimg>
<additionalimg>http://example.com/img/thumb/stock/antieyebrow_2.jpg</additionalimg>
<additionalimg>http://example.com/img/thumb/stock/antieyebrow_3.jpg</additionalimg>
</additionalimgs>
</piercing>
</piercings>
所以對於這一次我試圖用id="antieyebrow"
屬性拉的所有數據的piercing
。這是我試圖找回的東西。
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/info/piercing/piercings.xml')) {
$piercingxml = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/info/piercing/piercings.xml');
$location = $_GET['location'];
$piercingid = $piercingxml['id'];
}
else {
$piercingxml = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/info/piercing/default.xml');
$location = "default";
}
最後顯示的數據到頁面:
echo $piercingxml->$piercingid[$location]->title;
任何幫助,因爲在那裏我出了錯,將不勝感激。
這是有道理的,我喜歡它多麼簡單is.Thanks。 –