У меня есть XML-файл output.xmlЧтение XML-данных в PHP
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<key type="your_id">CYBEX-525A/DA-IPOD</key>
<key type="web">cybex-525at-arc-trainer</key>
<key type="web">standard-console-2573</key>
<key type="name">Cybex 525AT Arc Trainer</key>
<key type="name">Standard console</key>
<review>
<order_id>1544346 1</order_id>
<author_nick>Brock</author_nick>
<author_email>[email protected]</author_email>
<date type="accepted">2013-10-14</date>
<comment type="overall">This cardio machine is exceptional. It works every part of your leg muscles if you rotate through the height settings and include calf-raises and squats during your routine. It also works your shoulders and biceps if you focus on working them while operating the arm poles. Unlike a standard elliptical it will raise your heart rate and cause you to sweat heavily soon after you start your routine. If you're a runner and are used to using a treadmill, you will feel satisfied after using this machine. It is kind of addictive because your body feels so good during and after use. I have combined 30 minutes on the treadmill with 30 minutes on the Arc for weight-loss, muscle tone, and cardiovascular training.</comment>
<score type="overall">5</score>
</review>
</item>
</items>
Мне нужно, чтобы сохранить его в БД, я только с помощью кода ниже, чтобы сохранить данные
if(file_exists('output.xml')){
$languages = simplexml_load_file("output.xml");
//echo '<pre>'; print_r($languages) ; die;
foreach($languages as $item){
echo '<pre>'; print_r($item->key) ; die;
foreach($item->review as $review){
$order_id = $review[0]->order_id;
$authorName = $review[0]->author_nick;
$authorEmail = strtolower($review[0]->author_email);
$comment = $review[0]->comment;
$score = $review[0]->score;
$date = $review[0]->date;
}
}
}
мне нужно чтобы получить значение <key type="your_id">CYBEX-525A/DA-IPOD</key>
и <key type="web">cybex-525at-arc-trainer</key>
, но не смог получить данные , когда я печатать echo '<pre>'; print_r($item->key) ; die;
в цикле я получаю следующее из пут:
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => your_id
)
[0] => CYBEX-525A/DA-IPOD
[1] => cybex-525at-arc-trainer
[2] => standard-console-2573
[3] => Cybex 525AT Arc Trainer
[4] => Standard console
)
Есть ли способ получить все эти данные.
Почему вы звоните 'die' до достижения второго цикла? [die doc] (http://php.net/manual/en/function.die.php) – Ayak973
Поскольку мне нужен CYBEX-525A/DA-IPOD данные перед вторым контуром –
Arunendra