Cibiņš Posted May 8, 2012 Report Share Posted May 8, 2012 Ir dots xml fails ar aptuveni šādu contentu, kura struktūru nedrīkst mainīt. <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <smses count="3"> <sms protocol="0" address="+37122222222" date="1335616678978" type="1" subject="null" body="Testa iszina 1" toa="null" sc_toa="null" service_center="+37125850115" read="1" status="-1" locked="0" /> <sms protocol="0" address="+37122222222" date="1335872370593" type="2" subject="null" body="Testa iszina 2" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" /> <sms protocol="0" address="+37122222222" date="1335872373707" type="3" subject="null" body="Testa iszina 3" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" /> </smses> un tas jāizvada uz php $url = "sms-20120503200006.xml"; $xml = simplexml_load_file($url); foreach($xml->sms as $sms) { echo "<p>"; echo "<strong>Tips:</strong> ".$sms->address; echo "</p>"; echo "<p>"; echo "<strong>Adresats:</strong> ".$sms->address; echo "</p>"; echo "<p>"; echo "<strong>Zina:</strong> ".$sms->address; echo "</p>"; } Nesaprotu kā izvadīt loopu uz šo failu (neatspoguļo ierakstus), piem ja ir xml ar subnodiem tad viss čikiniekā. Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted May 8, 2012 Report Share Posted May 8, 2012 http://php.net/manual/en/simplexmlelement.attributes.php Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted May 8, 2012 Author Report Share Posted May 8, 2012 (edited) Šito jau lupīju..kodu man nevajag lai izvada, man vajag lai izvada tikai vērtības, kas ir iekš 'address', 'date', 'type' un 'body'. Piem: Adresāts: vērtība no 'address' Laiks: vērtība, kas konvertēta 'dd.mm.yyyy' no vērtības 'date', Tips: ja 1-ienākošā, ja 2-izejošā no vērtības 'type' Teksts: no vērtības 'body' apgaismojiet jel mani.. Edited May 8, 2012 by Cibiņš Quote Link to comment Share on other sites More sharing options...
marrtins Posted May 8, 2012 Report Share Posted May 8, 2012 $sms['address']? loopā nav jābūt foreach($smses...) ? Quote Link to comment Share on other sites More sharing options...
briedis Posted May 8, 2012 Report Share Posted May 8, 2012 Manuāli palasam, un visam vajadzētu būt skaidram... http://codepad.org/D8r11Mrr <? $xml = <<<XML <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <smses count="3"> <sms protocol="0" address="+37122222222" date="1335616678978" type="1" subject="null" body="Testa iszina 1" toa="null" sc_toa="null" service_center="+37125850115" read="1" status="-1" locked="0" /> <sms protocol="0" address="+37122222222" date="1335872370593" type="2" subject="null" body="Testa iszina 2" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" /> <sms protocol="0" address="+37122222222" date="1335872373707" type="3" subject="null" body="Testa iszina 3" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" /> </smses> XML; $xml = simplexml_load_string($xml); foreach($xml->sms as $sms) { echo "\n Tips: ".$sms['type']; echo " Adresats: ".$sms['address']; echo " Zina: ".$sms['body']; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.