2011-08-09 6 views
0

がどのように私は次のイベントPHP XML simple_loadのID

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

から "ID" を解析しない私はこのようなタイトルを解析:

$xml->event[0]->title 

答えて

2

のSimpleXML

$id_attribute = (string)$xml->event[0]->attributes()->id; 
attributesメソッドを使用します
2

あなたはaccess attributesのように連想配列の要素にアクセスするのと同じように:

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

戻り値はオブジェクト(__toStringメソッド)であるため、戻り値の型キャストが必要な場合があります。