Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$url = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$xml = simplexml_load_string($response);
if ($xml !== false) {
$currencies = $xml->xpath('/gesmes:Envelope//Cube[@currency]');
foreach ($currencies as $currency) {
$currencyCode = (string)$currency['currency'];
$exchangeRate = (float)$currency['rate'];
echo "Код валюты: $currencyCode, Курс: $exchangeRate\n";
}
} else {
echo "error2\n";
}
} else {
echo "error1\n";
}