Jump to content
php.lv forumi

xml faila saglabāšana


ray
 Share

Recommended Posts

Netā atrodas xml fails (LB valūtas kurss). Ar php mēģinu viņu saglabāt uz sava PC, bet kods īsti nestrādā, kāds varētu būt šīs kļūdas risinājums?

<?php
$xmlstr = file_get_contents("http://www.bank.lv/vk/xml.xml");
$dom = new domDocument;
$dom->loadXML($xmlstr);
$test = $dom->save("C:/save.xml");
echo "Fails saglabāts!;
?>

 

Warning: file_get_contents(http://www.bank.lv/vk/xml.xml) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\php\test2.php on line 3

Edited by ray
Link to comment
Share on other sites

  • 2 years later...

Ja ir interese, rekur jaunais LB valuutu kursa ieguushanas kods:

 

<?php

$doc = new DOMDocument();
$doc->load('http://www.bank.lv/lat/rss/kursi.php');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
	$itemRSS = array ( 
		'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
		'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
		'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue
		);
	array_push($arrFeeds, $itemRSS);
}
$pieces = explode(" ", $arrFeeds[0]['desc']);

$kursi = array();
$key = false;
For ($k=1; $k<sizeof($pieces); $k++) {
	if (!$key) {
		$key = $pieces[$k];
	} else {
		$kursi[$key] = $pieces[$k];
		$key = false;
	}
}

echo "<pre>"; print_r($kursi); echo "</pre>";

?>

Link to comment
Share on other sites

 Share

×
×
  • Create New...