Jump to content
php.lv forumi

XML Parse


aaxc

Recommended Posts

Sveiki,

uzreiz saku, ka es jautaajums ir noobisks.

 

Es te pus nakti njemos un taa arii nesaprotu, kaa pareizi ieguut latvijas bankas valuutu kursus masiivaa.

 

Esmu ticis liidz pasham sakumama:

 

Function myKursi() { // ieguustam kursus, ja shii ir pirmaa reize kad piesleedzamies bankai
GLOBAL $BankXML; // links $BankXML = "http://www.bank.lv/vk/xml.xml";

$masiivs = simplexml_load_file($BankXML);

foreach (simplexml_load_string($dati) as $virsraksts => $maziivs) { // Apstraadaajam ieguuto masiivu
	switch ($virsraksts) {
		// Paarveidojam datumu GERMAN formaataa
		case "Date":
			$datums = substr($maziivs[0],6,2).".".substr($maziivs[0],4,2).".".substr($maziivs[0],0,4);
		break;
		case "Currencies";
			$kursi = $maziivs["Currency"];

			foreach (simplexml_load_file($BankXML) as $virsraksts => $maziivs) {
				echo "<pre>";
				print_r($maziivs);
				echo "</pre>";
                       }
		break;
	}
}

}

 

Pie "echo" stadijas es dabuunu scriptu objekta formaataa un namaaku to dabuut standarta masiivaa, lai peec tam to apstraadaatu un izvaidotu "excel" tipa tabulaa.

 

Any help?

Link to comment
Share on other sites

Pie tam vari beigās piespraust $xml = $xml->as_array(); un tas būs masīvs.

 

Ja nevari, tad noteikti vari $xml = (array) $xml;. Masīvs!

 

Ja tā arī nesanāk, tad ignorē Manu postu.

 

Protams, vispār, ja Tev vajag masīvu. Var jau darīt kā M teica.

Link to comment
Share on other sites

Paldies par padomiem, izdomāju kā. Rīts tomēr gudrāks par vakaru :)

 

Function myKursi() {
GLOBAL $BankXML;

$dati = simplexml_load_file($BankXML);

$datums = $dati->Date;
$vDatums = substr($datums,6,2).".".substr($datums,4,2).".".substr($datums,0,4);

$kursi = $dati->Currencies;
foreach ($kursi->Currency as $valuta) {
	$vID = $valuta->ID;
	$vUnits = $valuta->Units;
	$vRate = $valuta->Rate;	
}
}

Edited by aaxc
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...