$url='http://www.cbr.ru/scripts/XML_daily.asp?date_req=01/01/2007&d=1' ;
$context = array(
'http'=>array('max_redirects' => 1)
);
$context = stream_context_create($context);
if (!($fp = fopen($url,"r", false, $context))) {
die("could not open XML input");
}
function parseResponse( $response )
{
$response_parts = explode( "\r\n\r\n", $response, 2 );
$response = array();
$cookie = array();
$response['header'] = explode( "\r\n", $response_parts[0] );
if ( preg_match_all( '/Set-Cookie: (.*?)=(.*?)(\n|;)/i', $response_parts[0], $matches ) ) {
if ( !empty( $matches ) ) {
foreach ( $matches[1] as $key => $value ) {
$cookie[] = $value . '=' . $matches[2][$key] . ';';
}
$response['cookie'] = $cookie;
}
}
$response['body'] = $response_parts[1];
return $response;
}
$url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=10/12/2013';
$request = curl_init( $url );
$options = array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0',
);
curl_setopt_array( $request, $options );
$result = curl_exec( $request );
if ( $result ) {
$info = curl_getinfo( $request );
$response = parseResponse( $result );
$response['info'] = $info;
} else {
$response = array(
'number' => curl_errno( $request ),
'error' => curl_error( $request ),
'info' => curl_getinfo( $request )
);
}
curl_close( $request );
print_r( $response );
https://www.cbr-xml-daily.ru/
https://www.cbr-xml-daily.ru/daily.xml
https://www.cbr-xml-daily.ru/daily_utf8.xml
https://www.cbr-xml-daily.ru/daily_eng.xml
https://www.cbr-xml-daily.ru/daily_eng_utf8.xml
https://www.cbr-xml-daily.ru/daily_json.js
https://www.cbr-xml-daily.ru/daily_jsonp.js
<div id="USD">Доллар США $ — 00,0000 руб.</div>
<div id="EUR">Евро € — 00,0000 руб.</div>
<script>
function CBR_XML_Daily_Ru(rates) {
var USDrate = rates.Valute.USD.Value.toFixed(4).replace('.', ',');
var USD = document.getElementById('USD');
USD.innerHTML = USD.innerHTML.replace('00,0000', USDrate);
var EURrate = rates.Valute.EUR.Value.toFixed(4).replace('.', ',');
var EUR = document.getElementById('EUR');
EUR.innerHTML = EUR.innerHTML.replace('00,0000', EURrate);
}
</script>
<script src="https://www.cbr-xml-daily.ru/daily_jsonp.js"></script>
$URL = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=10/12/2013';
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS,1);
$sistem = curl_exec($ch);
var_dump($sistem);
curl_close($ch);
$xml = new DOMDocument();
$current = file_get_contents('http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . date('d.m.Y'));
$file = __DIR__ . '-currensy.xml';
file_put_contents($file, $current);
if (@$xml->load($file)) {
$this->list = array();
$root = $xml->documentElement;
$items = $root->getElementsByTagName('Valute');
foreach ($items as $item) {
$code = $item->getElementsByTagName('CharCode')->item(0)->nodeValue;
$curs = $item->getElementsByTagName('Value')->item(0)->nodeValue;
$this->list[$code] = floatval(str_replace(',', '.', $curs));
}
unlink($file);
return true;
}
else
unlink($file);
return false;