Question: Design a currency conversion app using PHP and the publicly available API: https://free.currencyconverterapi.com/ Modify the starter code in meaningful ways. You will probably not need

Design a currency conversion app using PHP and the publicly available API: https://free.currencyconverterapi.com/

Modify the starter code in meaningful ways. You will probably not need to change the currency Converter function!

Here's the starter code:

Convert.php

include_once("functions.php");

if(isset($_POST['convert'])) {

$from_currency = trim($_POST['from_currency']);

$to_currency = trim($_POST['to_currency']);

$amount = trim($_POST['amount']);

if($from_currency == $to_currency) {

$data = array('error' => '1');

echo json_encode( $data );

exit;

}

$converted_currency=currencyConverter($from_currency, $to_currency, $amount);

// Print outout

echo $converted_currency;

}

?>

functions.php

function currencyConverter($from_Currency,$to_Currency,$amount) {

$from_Currency = urlencode($from_Currency);

$to_Currency = urlencode($to_Currency);

$get = file_get_contents("");

$get = explode("",$get);

$get = explode("",$get[1]);

$rate= preg_replace("/[^0-9\.]/", null, $get[0]);

$converted_amount = $amount*$rate;

$data = array( 'rate' => $rate, 'converted_amount' =>$converted_amount, 'from_Currency' => strtoupper($from_Currency), 'to_Currency' => strtoupper($to_Currency));

echo json_encode( $data );

}

?>

index.php

include('header.php');

?>

phpzag.com : Demo Currency conversion in PHP Using API

Example: Currency conversion in PHP Using API




Back to Tutorial

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!