我已经成功检索了xml文件并将其打印为数组,但是我想要做的是遍历文件并在每条记录上执行一些操作。 我尝试了-> children的foreach循环,但我似乎无法打印任何内容
$curl = curl_init();
curl_setopt_array($curl, Array(
CURLOPT_URL => 'http://www.test.co.uk/test.xml',
CURLOPT_USERAGENT => 'spider',
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => 'UTF-8'
));
$data = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
//die('<pre>' . print_r($xml, TRUE) . '</pre>');
echo $xml->row[0]['user'];
die();
数组中的数据如下:
<pre>SimpleXMLElement Object
(
[row] => Array
(
[0] => SimpleXMLElement Object
(
[user] => aaa
[enabled] => 1
[email_address] => aaa@gmail.com
[OrderDate] => 2018-08-01 10:25:04
[products_id] => 381
[NewOrder] => 0
[ResendKeys] => 0
[LastUpdate] => 2018-12-19 02:36:26
)
[1] => SimpleXMLElement Object
(
[user] => bbb
[enabled] => 1
[email_address] => bbb@gmail.com
[OrderDate] => 2018-12-19 02:50:27
[products_id] => 380
[NewOrder] => 0
[ResendKeys] => 1
[LastUpdate] => 2018-12-19 02:50:27
)