Hi, I have a small problem. I need to get data from a xml that looks like this: <offers> [INDENT]<offerID>xxxx</offerID> <offerName>ioahdf9uafaewfa</offerName> <offerNameInternal>dfsasdfasfadsfadsfdsa</offerNameInternal><trackingUrl>http://afdasfasfdasfdasf</trackingUrl> <payout>xxx</payout> <countries>xx</countries> <offerID>xxxx</offerID> <offerName>oifahofafa</offerName> <offerNameInternal>asdafafasf</offerNameInternal> <trackingUrl>http://sadffdadsdasvsavsad</trackingUrl> <payout>xxx</payout> <countries>xxx</countries>[/INDENT] </offers> Code (markup): How can I group these in php so I can get them with foreach($xml-offer as $offer) PHP: or something like this. Thank you!
if you read it from a file http://php.net/manual/en/function.simplexml-load-file.php if you read it from a string http://php.net/manual/en/function.simplexml-load-string.php Google is your friend
No offense but i've already read the manuals and I don't seem to find a solution. I wouldn't have posted here if the solution was/is found on google or php.net or w3schools or stackoverflow!!!!
Looks like you can use XMLReader class to iterate over every xml node and collect necessary information. Or if you are sure if you have regular xml structure (equal numbers of any tag inside <offers>) you can parse it with regex and just select data with equal indexes.
Hi...Please check following URL . It may help you. <br>http://php.net/manual/en/simplexml.examples-basic.php</br> <br>http://php.net/manual/en/class.xmlreader.php</br> HTML:
I've solved the problem! For anyone interested i did it like this: I've created an array from the xml feed $array=json_decode(json_encode($xml),true); PHP: And after that i've combined the arrays using MultipleIterator like this: $mi = new MultipleIterator(); $mi->attachIterator(new ArrayIterator($array1)); $mi->attachIterator(new ArrayIterator($array2)); $mi->attachIterator(new ArrayIterator($array3)); foreach ( $mi as $value ) { list($offerid, $offername, $offerinternalname) = $value; echo $offerid , ' => ' , $offername , ' => ' , $offerinternalname ; } PHP: And that's how i've got them to the database!