开发者

PHP XML simple_load id

开发者 https://www.devze.com 2023-03-27 01:23 出处:网络
How do I parse \"id\" from the following event <event id=\"100990\"> <title>myTitle</title>

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

精彩评论

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