I have the following xml being returned when using fsockopen (shortened the xml for ease of reading):
我在使用fsockopen时会返回以下xml(为了便于阅读,缩短了xml):
<car>
<brand type="AUDI">
<engine>1.8</engine>
<price>9000</price>
</brand>
</car>
I use the following code to get the values:
我使用以下代码来获取值:
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_parse_into_struct($p, $return_xml, $vals, $index);
xml_parser_free($p);
$return_array["engine"] = $vals[$index["engine"][0]]["value"];
$return_array["price"] = $vals[$index["price"][0]]["value"];
Which gives me the engine, and price but how can I get the value brand type?
这给了我引擎和价格,但我怎样才能获得价值品牌类型?
Thanks
谢谢
1 个解决方案
#1
1
xml_parser is the oldest and cruddiest of the XML implementations in PHP. I would recommend using SimpleXML, as it's OO oriented and a bit easier to use.
xml_parser是PHP中最古老,最肮脏的XML实现。我建议使用SimpleXML,因为它面向OO并且更容易使用。
With SimpleXML you could do:
使用SimpleXML,您可以:
$car->brand[0]['type'];
Check it out:
一探究竟:
http://www.php.net/manual/en/simplexml.examples-basic.php
http://www.php.net/manual/en/simplexml.examples-basic.php
#1
1
xml_parser is the oldest and cruddiest of the XML implementations in PHP. I would recommend using SimpleXML, as it's OO oriented and a bit easier to use.
xml_parser是PHP中最古老,最肮脏的XML实现。我建议使用SimpleXML,因为它面向OO并且更容易使用。
With SimpleXML you could do:
使用SimpleXML,您可以:
$car->brand[0]['type'];
Check it out:
一探究竟:
http://www.php.net/manual/en/simplexml.examples-basic.php
http://www.php.net/manual/en/simplexml.examples-basic.php