Maharashtra State Board of Technical Education Bijapure Mohammad Afraz Sarfaraz Nawaz Mrs. B.S.Mali
Maharashtra State Board of Technical Education Bijapure Mohammad Afraz Sarfaraz Nawaz Mrs. B.S.Mali
Project Report On
“Currency Converter using PHP”
Submitted in Partial Fulfillment of the Requirement
For the Award of Diploma
In “Computer Science and Engineering” of
Government Polytechnic College, Dharashiv
Affiliated to
CERTIFICATE
This is certify that Mr. Bijapure Mohammad Afraz Sarfaraz Nawaz Roll no. 63 of
sixth Semester of Diploma in Computer Engineering of Institute Government
Polytechnic, Dharashiv (0118) has completed the Micro-project satisfactory in
subject PHP (22619) for the academic year 2023-2024 as prescribed in the
curriculum.
Seal of Institute
ACKNOWLEDGEMENT
I am sincerely grateful for the guidance and support provided by Mrs. Mali Mam
throughout the development of the Currency Converter project. This project has
offered me a wealth of knowledge and insight of intricacies of developing a
comprehensive software. I extend my heartfelt appreciation for this incredible
opportunity.
I would also like to extend my gratitude to my friends for their unwavering support
and assistance in successfully completing this project within the specified time
constraints.
I express my heartfelt gratitude once again for invaluable guidance and support
provided throughout the endeavour.
Sincerely,
Bijapure Afraz
INDEX
The rationale for undertaking a micro project on creating a currency converter in PHP lies in its
practical utility and educational value. In an increasingly interconnected world, where businesses
and individuals engage in transactions across borders, having a tool to swiftly convert currencies is
invaluable. By developing this project, I aim to hone my PHP programming skills, particularly in
handling user inputs, implementing mathematical algorithms for currency conversion, and
presenting results in a user-friendly interface. Additionally, this project offers an opportunity to
deepen my understanding of web development principles, including data validation, and responsive
design. Ultimately, the currency converter project serves as a tangible application of PHP
programming concepts while addressing a real-world need, facilitating financial transactions and
enhancing my proficiency in web development.
Benefits:
• Practical Utility
• Learning Experience
• Skill Enhancement
• Exploration of Advanced Features
5
4.0 Literature Review:
The creation of currency converters using PHP is a common application of web development
technologies, facilitating seamless currency exchange processes for users across the globe. This
literature review aims to explore key aspects relevant to the development of PHP-based currency
converters, including currency conversion algorithms, web development best practices, API
integration, user interface design, and security considerations.
6
INTRODUCTION
Introduction to PHP:
PHP, which stands for Hypertext Preprocessor, is a widely-used open-source scripting language
primarily designed for web development. Originally created by Danish-Canadian programmer
Rasmus Lerdorf in 1994, PHP has evolved into one of the most popular server-side scripting
languages for creating dynamic and interactive web pages.
• Server-Side Scripting: PHP is executed on the server-side, meaning it runs on the web
server before the resulting HTML is sent to the client's web browser. This enables PHP to
generate dynamic content, interact with databases, and perform various server-side tasks.
•
• Embedded in HTML: PHP code can be seamlessly embedded within HTML, allowing
developers to mix PHP with standard HTML markup. This facilitates the creation of
dynamic web pages by enabling the integration of PHP scripts with HTML for generating
dynamic content.
•
• Cross-Platform Compatibility: PHP is compatible with major operating systems such as
Windows, Linux, macOS, and various web servers like Apache, Nginx, and Microsoft IIS.
This cross-platform compatibility ensures that PHP applications can run on a wide range of
environments.
•
• Extensive Library Support: PHP has a vast ecosystem of libraries, frameworks, and
extensions that extend its functionality and streamline web development. Popular PHP
frameworks such as Laravel, Symfony, and CodeIgniter provide pre-built components and
tools for building robust web applications efficiently.
•
• Database Integration: PHP offers seamless integration with databases, allowing developers
to interact with relational databases like MySQL, PostgreSQL, and SQLite. This enables the
creation of dynamic web applications with features such as user authentication, content
management, and e-commerce functionality.
7
Common Use Cases of PHP:
• Dynamic Web Pages: PHP is commonly used to create dynamic web pages that generate
content based on user inputs, database queries, or external data sources. This enables the
creation of interactive websites with features such as user authentication, form processing,
and content management systems.
•
• Web Application Development: PHP is widely used for developing web applications
ranging from simple blogs and e-commerce platforms to complex enterprise applications. Its
versatility, scalability, and extensive library support make it a popular choice for building a
wide range of web-based solutions.
•
• API Development: PHP can be used to create APIs (Application Programming Interfaces)
for building RESTful web services and integrating with external applications or services.
APIs developed in PHP enable communication between different software systems,
facilitating data exchange and interoperability.
Currency conversion is a common necessity in today's globalized world, where individuals and
businesses frequently engage in international transactions. A currency converter is a valuable tool
that allows users to convert the value of one currency into another based on prevailing exchange
rates. In this context, PHP provides an efficient and versatile platform for creating currency
converter applications that can be seamlessly integrated into websites or web applications.
• User Interface: The currency converter interface typically consists of input fields for
specifying the amount to be converted, dropdown menus for selecting the source and target
currencies, and a button to initiate the conversion process. PHP is used to generate dynamic
HTML content and handle user interactions on the server-side.
•
• Exchange Rate Retrieval: PHP facilitates the retrieval of exchange rate data from external
sources such as currency exchange rate APIs. These APIs provide real-time or historical
exchange rate information for different currency pairs, enabling accurate currency
conversion calculations within the PHP application.
8
• Currency Conversion Algorithm: PHP implements the logic for performing currency
conversion calculations based on the input amount and retrieved exchange rates. This
involves multiplying the input amount by the exchange rate of the selected target currency
relative to the source currency to determine the converted amount.
•
• Error Handling: PHP code incorporates error handling mechanisms to gracefully manage
scenarios such as invalid user inputs, API request failures, or unexpected errors during
currency conversion. Error messages are displayed to users to provide feedback and guide
them in correcting input errors or resolving issues.
•
• Output Display: Upon successful currency conversion, PHP generates HTML output to
display the converted amount along with relevant currency symbols and labels. The
converted amount is presented to users in a clear and understandable format, ensuring a
seamless user experience.
In summary, a currency converter using PHP provides a practical and effective solution for
facilitating currency conversion tasks within web-based applications. With its robust features,
flexibility, and extensive community support, PHP empowers developers to create reliable and user-
friendly currency converter applications that meet the needs of users in today's interconnected
global economy.
9
5.0 Actual Methodology Followed:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Currency Converter</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-image: url('blue-curve-
background_53876-113112.jpg.avif');
background-size: cover;
background-repeat: no-repeat;
}
.converter {
width: 80%; /* Set a percentage value */
max-width: 400px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
input[type="number"] {
display: block;
width: calc(100% - 20px); /* Adjusted width */
margin-bottom: 10px;
10
padding: 10px;
box-sizing: border-box; /* Include padding in the
width calculation */
}
input[type="number"]::placeholder {
font-size: 0.8em; /* Adjusted font size for the
placeholder */
}
input[type="number"]:focus {
outline: none; /* Remove default focus style */
}
select, button {
display: block;
width: 100%;
margin-bottom: 10px;
padding: 10px;
}
button {
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.result {
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="converter">
<h2>Currency Converter</h2>
11
<form action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<input type="number" name="amount"
placeholder="Amount" step="any" required>
<select name="from_currency" required>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="AUD">AUD</option>
<option value="CAD">CAD</option>
<option value="JPY">JPY</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="INR">INR</option>
<option value="SGD">SGD</option>
<option value="HKD">HKD</option>
<option value="NZD">NZD</option>
<option value="MXN">MXN</option>
<option value="BRL">BRL</option>
<option value="SAR">SAR</option>
<option value="AED">AED</option>
<option value="KRW">KRW</option>
<option value="THB">THB</option>
<option value="RUB">RUB</option>
<option value="TRY">TRY</option>
<option value="IDR">IDR</option>
<option value="PHP">PHP</option>
<option value="ZAR">ZAR</option>
<option value="PLN">PLN</option>
<option value="SEK">SEK</option>
<option value="NOK">NOK</option>
<option value="DKK">DKK</option>
<option value="HUF">HUF</option>
<option value="CZK">CZK</option>
<option value="ILS">ILS</option>
<option value="ISK">ISK</option>
<option value="MYR">MYR</option>
<option value="RON">RON</option>
<option value="HRK">HRK</option>
<option value="KWD">KWD</option>
</select>
<select name="to_currency" required>
12
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="AUD">AUD</option>
<option value="CAD">CAD</option>
<option value="JPY">JPY</option>
<option value="CHF">CHF</option>
<option value="CNY">CNY</option>
<option value="INR">INR</option>
<option value="SGD">SGD</option>
<option value="HKD">HKD</option>
<option value="NZD">NZD</option>
<option value="MXN">MXN</option>
<option value="BRL">BRL</option>
<option value="SAR">SAR</option>
<option value="AED">AED</option>
<option value="KRW">KRW</option>
<option value="THB">THB</option>
<option value="RUB">RUB</option>
<option value="TRY">TRY</option>
<option value="IDR">IDR</option>
<option value="PHP">PHP</option>
<option value="ZAR">ZAR</option>
<option value="PLN">PLN</option>
<option value="SEK">SEK</option>
<option value="NOK">NOK</option>
<option value="DKK">DKK</option>
<option value="HUF">HUF</option>
<option value="CZK">CZK</option>
<option value="ILS">ILS</option>
<option value="ISK">ISK</option>
<option value="MYR">MYR</option>
<option value="RON">RON</option>
<option value="HRK">HRK</option>
<option value="KWD">KWD</option>
</select>
<button type="submit">Convert</button>
</form>
<?php
13
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$amount = $_POST['amount'];
$from_currency = $_POST['from_currency'];
$to_currency = $_POST['to_currency'];
$base_url = "https://api.exchangerate-api.com/v4/
latest/{$from_currency}";
$response = file_get_contents($base_url);
$data = json_decode($response, true);
if ($data['error']) {
echo "Error: {$data['error']}";
exit();
}
$exchange_rate = $data['rates'][$to_currency];
$converted_amount = $amount * $exchange_rate;
14
Output of code:
15
Image 3 : Choosing amount
16
6.0 Actual Resources Used :
i. PHP Programming
ii. API Integration
iii. Error Handling
iv. HTML/CSS
8.0 Applications :
i. E-commerce websites
ii. Mobile Apps
iii. Global freelancing
iv. Global Marketing
17
Conclusion :
In conclusion, creating a currency converter micro project using PHP has been a valuable learning
experience. Through this project, we have gained hands-on experience in PHP programming, API
integration, data handling, and user interface design. We have learned how to fetch real-time
exchange rates from external sources, perform currency conversions, and display results in a user-
friendly manner. This project has also helped us improve our problem-solving skills, as we
encountered various challenges such as error handling, security considerations, and performance
optimization.
References :
i. openai.com
ii. php.net
iii. github.com
iv. exchangerate-api.com
18