2011-08-09 25 views
0

如何解析 「ID」,從以下事件PHP的XML simple_load ID

<event id="100990"> 
    <title>myTitle</title> 
</event> 

我分析標題是這樣的:

$xml->event[0]->title 

回答

2

使用的SimpleXML

attributes方法
$id_attribute = (string)$xml->event[0]->attributes()->id; 
2

access attributes就像你會訪問一個關聯數組的元素:

$xml_node['id'] // The value of the attribute `id` of the node `$xml_node` 

返回的值是一個對象(使用__toString方法),因此您可能需要對返回的值進行類型轉換。