从通过 php fsockopen 返回的 xml 中获取值
使用 fsockopen 时返回以下 xml(为了便于阅读而缩短了 xml):
<car>
<brand type="AUDI">
<engine>1.8</engine>
<price>9000</price>
</brand>
</car>
我使用以下代码来获取值:
$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"];
这给了我引擎和价格,但如何获取价值品牌类型?
谢谢
I have the following xml being returned when using fsockopen (shortened the xml for ease of reading):
<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
xml_parser 是 PHP 中最古老、最粗糙的 XML 实现。我建议使用 SimpleXML,因为它是面向对象的并且更容易使用。
使用 SimpleXML 你可以这样做:
看看:
http://www.php .net/manual/en/simplexml.examples-basic.php
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.
With SimpleXML you could do:
Check it out:
http://www.php.net/manual/en/simplexml.examples-basic.php