ray Posted March 10, 2008 Report Share Posted March 10, 2008 (edited) 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 March 10, 2008 by ray Link to comment Share on other sites More sharing options...
Vebers Posted March 10, 2008 Report Share Posted March 10, 2008 Timeouts. Varētu būt ka nav tajā brīdi tas LB serveris pieejams. Vari pamēģināt soketus, tur to timeoutus var pats norādīt. Link to comment Share on other sites More sharing options...
ray Posted March 10, 2008 Author Report Share Posted March 10, 2008 Caur webisko interfeisu xml fails ir atverams, palaižot php skriptu rādās šī kļūda. cita risinājuma bez soketiem nav? Link to comment Share on other sites More sharing options...
Vebers Posted March 10, 2008 Report Share Posted March 10, 2008 cURL - bibliotēka soketiem (vieglāk lietojama kā plain soketi). Link to comment Share on other sites More sharing options...
aaxc Posted August 18, 2010 Report Share Posted August 18, 2010 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 More sharing options...
Recommended Posts