开发者

PHP XML simple_load id

How do I parse "id" from the following event

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

I parse the title like this:开发者_如何学C

$xml->event[0]->title


Use the attributes method of SimpleXML

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


You access attributes just like you would access elements of an associative array:

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

The returned value is an object (with a __toString method), so you may want to typecast the returned value.


This is exactly what you need: http://www.php.net/manual/en/simplexmlelement.attributes.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜