如何使用PHP将美元更改为印度卢比

如何使用PHP将美元更改为印度卢比,php,Php,我正在搜索PHP中美元到印度卢比的转换器。我在StackOverflow上找到了许多解决方案,但这些都不起作用 我试过这个密码- <?php $amount = 1.00; $from_Currency = 'USD'; $to_Currency = 'INR'; $amount = urlencode($amount); $from_Currency = urlencode($from_Currency); $to_Currency = urlencode($to_Currency);

我正在搜索PHP中美元到印度卢比的转换器。我在StackOverflow上找到了许多解决方案,但这些都不起作用

我试过这个密码-

<?php

$amount = 1.00;
$from_Currency = 'USD';
$to_Currency = 'INR';
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
$get = explode("<span class=bld>",$get);
$get = explode("</span>",$get[1]);
echo $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);


?>

它只产生了0的价值。并非所有的解决方案都适用于我。我尝试了StackOverflow的所有解决方案

在浏览器中打开要发送请求的url。它工作吗?不,它不工作。我已经发布了答案,这个api工作了。是的,非常感谢。是的,它工作了。谢谢你,Sachin。你能投票支持这个答案吗?你有其他使用谷歌API的解决方案吗?谷歌去年对他们的API做了一些修改,现在大部分API都是付费的。恐怕他们让我付钱了。让我帮你检查一下。我已经试过你的代码,但执行起来要花很多时间。
// Fetching JSON
$req_url = 'https://api.exchangerate-api.com/v4/latest/USD';
$response_json = file_get_contents($req_url);

// Continuing if we got a result
if(false !== $response_json) {

    // Try/catch for json_decode operation
    try {

    // Decoding
    $response_object = json_decode($response_json);

    // YOUR APPLICATION CODE HERE, e.g.
    $base_price = 1; // Your price in USD
    echo $INR_price = round(($base_price * $response_object->rates->INR), 2);

    }
    catch(Exception $e) {
        // Handle JSON parse error...
    }
}
// Fetching JSON
$req_url = 'https://api.exchangerate-api.com/v4/latest/USD';
$response_json = file_get_contents($req_url);

// Continuing if we got a result
if(false !== $response_json) {

    // Try/catch for json_decode operation
    try {

    // Decoding
    $response_object = json_decode($response_json);

    // YOUR APPLICATION CODE HERE, e.g.
    $base_price = 1; // Your price in USD
    echo $INR_price = round(($base_price * $response_object->rates->INR), 2);

    }
    catch(Exception $e) {
        // Handle JSON parse error...
    }
}