Search code examples
phpjsoncurrency

Print JSON data from currencyconverterapi


I'm trying to print the value from currency converter API JSON data.

Anyone can help me to print the value from this URL

https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y?


Solution

  • You have to use file_get_contents() along with json_decode()

    <?php
    
    $json_data = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y');
    
    $array = json_decode($json_data, true);
    
    var_dump($array["USD_IDR"]["val"]);
    
    ?>
    

    I have tested it on the local machine and working fine:-

    https://prnt.sc/jd1kxo And https://prnt.sc/jd1l7w