Перейти к содержимому


Фотография
- - - - -

как настроить свой конвертер в файле jbcurrency.xml


  • Закрытая тема Тема закрыта
Сообщений в теме: 10

#11 RomanL

RomanL

Отправлено 31 January 2013 - 16:16

Не хватает времени...
Можете попробовать такую функцию (с сайта php.net)

A wrapper around simplexml_load_file to circumvent nasty error messages when the xml server times out or gives a 500 error etc. 

<?php 
function loadXML2($domain, $path, $timeout = 30) { 

    /* 
        Usage: 
        
        $xml = loadXML2("127.0.0.1", "/path/to/xml/server.php?code=do_something"); 
        if($xml) { 
            // xml doc loaded 
        } else { 
            // failed. show friendly error message. 
        } 
    */ 

    $fp = fsockopen($domain, 80, $errno, $errstr, $timeout); 
    if($fp) { 
        // make request 
        $out = "GET $path HTTP/1.1\r\n"; 
        $out .= "Host: $domain\r\n"; 
        $out .= "Connection: Close\r\n\r\n"; 
        fwrite($fp, $out); 
        
        // get response 
        $resp = ""; 
        while (!feof($fp)) { 
            $resp .= fgets($fp, 128); 
        } 
        fclose($fp); 
        // check status is 200 
        $status_regex = "/HTTP\/1\.\d\s(\d+)/"; 
        if(preg_match($status_regex, $resp, $matches) && $matches[1] == 200) {    
            // load xml as object 
            $parts = explode("\r\n\r\n", $resp);    
            return simplexml_load_string($parts[1]);                
        } 
    } 
    return false; 
    
} 
?>

  • 0
[color=#aa0000]Не забывайте нажимать кнопку «Вопрос Решён» и «+1» под сообщением, которое Вам помогло[/color]




Click to return to top of page in style!