Welcome to the UnirateAPI PHP documentation! Our free exchange rate API provides real-time currency conversion capabilities that you can easily integrate into your PHP applications. Whether you're building a financial application, e-commerce platform, or any other system that needs currency conversion, our API has you covered.
UnirateAPI is designed to be developer-friendly and reliable, with a focus on simplicity and performance. Our PHP implementation uses native cURL for HTTP requests, making it compatible with any PHP environment without requiring additional dependencies. The API returns JSON responses that can be easily parsed using PHP's built-in JSON functions.
For more detailed information about our API endpoints, rate limits, and advanced features, please check our main API documentation.
The example below shows you how to integrate our API into your PHP application in just a few lines of code.
Our Currency Convertor API is easy to integrate with PHP applications. Below you'll find a complete example of how to use our API.
// Example of using the Unirate API with PHP
$api_key = 'YOUR_API_KEY';
$base_url = 'https://api.unirateapi.com/api';
// Function to convert currency
function convertCurrency($from, $to, $amount) {
global $api_key, $base_url;
$url = "{$base_url}/convert?api_key={$api_key}&from={$from}&to={$to}&amount={$amount}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
return json_decode($response, true);
} else {
throw new Exception('API request failed: ' . $response);
}
}
// Example usage
try {
$result = convertCurrency('USD', 'EUR', 100);
echo "Converted amount: " . $result['result'] . " " . $result['to'];
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
{
"from": "USD",
"to": "EUR",
"amount": 100,
"result": 92.45,
}
Sign up now to get your API key and start converting currencies in your php applications.
Get Your API Key