Jump to content
php.lv forumi

PHP + XML


Cibiņš

Recommended Posts

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ā.

Link to comment
Share on other sites

Š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 by Cibiņš
Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...