【发布时间】:2015-12-14 14:52:13
【问题描述】:
我面临以下 XML:
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_PURCHASE_VALUTA
[valid_from] => 2015-12-14 13:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.0266
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.326
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.4771
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 26.0743
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 19.5504
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_SALE_DEVIZA
[valid_from] => 2015-12-14 13:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 18.1262
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.6161
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.7017
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 27.5739
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 20.813
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_PURCHASE_DEVIZA
[valid_from] => 2015-12-14 13:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.34581
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.46043
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.54232
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 26.46609
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 19.91697
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_MIDDLE
[valid_from] => 2015-12-14 13:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.736
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.53827
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.622
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 27.02
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 20.365
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_SALE_VALUTA
[valid_from] => 2015-12-12 00:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 18.3578
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.6435
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.7488
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 27.8306
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 21.0322
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_PURCHASE_VALUTA
[valid_from] => 2015-12-12 00:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.0275
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.3251
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.4771
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 26.0743
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 19.5082
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_SALE_DEVIZA
[valid_from] => 2015-12-12 00:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 18.1272
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.6152
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.7017
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 27.5739
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 20.7681
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_PURCHASE_DEVIZA
[valid_from] => 2015-12-12 00:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.34679
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.45955
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.54232
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 26.46609
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 19.87394
)
)
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => XML_RATE_TYPE_EBNK_MIDDLE
[valid_from] => 2015-12-12 00:00:00.0
)
[currency] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => AUD
[quota] => 1
[rate] => 17.737
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => HRK
[quota] => 1
[rate] => 3.53737
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => DKK
[quota] => 1
[rate] => 3.622
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => EUR
[quota] => 1
[rate] => 27.02
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => JPY
[quota] => 100
[rate] => 20.321
)
)
)
)
我根本不熟悉 XML。我一直使用 JSON。我需要从 XML 返回 2 个数组。一定要听具体情况。
我只需要类型从今天开始有效的[currency] 数组。喜欢
[valid_from] => date('Y-m-d')
XML 的在线 URL:
我需要两个数组之一:
@type:XML_RATE_TYPE_EBNK_PURCHASE_DEVIZA
@valid_from:2015-12-12 00:00:00.0
和
@type:XML_RATE_TYPE_EBNK_SALE_DEVIZA
@valid_from:2015-12-12 00:00:00.0
【问题讨论】:
-
有点像 hack,但并不总是最好的主意,但如果您对 JSON(或本机数组)更满意,您可以使用
$json = json_encode(simplexml_load_file($path));将其转换为本机数组,然后您可以 @ 987654328@它。
标签: php xml codeigniter