Here is a Loan EMI (Equated Monthly Installment) Calculator using PHP that allows users to calculate their loan EMI based on the loan amount, interest rate, and loan tenure.
1. PHP Code for Loan EMI Calculator Tool
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Loan EMI Calculator Tool to calculate monthly installments."> <meta name="keywords" content="EMI Calculator, Loan Calculator, PHP, Loan EMI"> <title>Loan EMI Calculator</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .container { max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { text-align: center; } form { margin-top: 20px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input[type="text"], select, input[type="submit"] { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 5px; } input[type="submit"] { background-color: #007bff; color: #fff; cursor: pointer; } .result { font-size: 18px; text-align: center; color: #333; } .error { color: red; text-align: center; } </style> </head> <body> <div class="container"> <h1>Loan EMI Calculator</h1> <p>Enter the loan amount, interest rate, and loan tenure to calculate the EMI.</p> <form method="post"> <label for="loan_amount">Loan Amount:</label> <input type="text" id="loan_amount" name="loan_amount" placeholder="Enter loan amount" required> <label for="interest_rate">Annual Interest Rate (%):</label> <input type="text" id="interest_rate" name="interest_rate" placeholder="Enter interest rate" required> <label for="loan_tenure">Loan Tenure (in months):</label> <input type="text" id="loan_tenure" name="loan_tenure" placeholder="Enter loan tenure in months" required> <input type="submit" name="calculate_emi" value="Calculate EMI"> </form> <?php if (isset($_POST['calculate_emi'])) { $loan_amount = $_POST['loan_amount']; $interest_rate = $_POST['interest_rate']; $loan_tenure = $_POST['loan_tenure']; // Validate input if (!is_numeric($loan_amount) || !is_numeric($interest_rate) || !is_numeric($loan_tenure)) { echo "<div class='error'>Please enter valid numeric values.</div>"; } elseif ($loan_amount <= 0 || $interest_rate <= 0 || $loan_tenure <= 0) { echo "<div class='error'>All values must be greater than zero.</div>"; } else { // Convert interest rate to monthly rate $monthly_rate = ($interest_rate / 12) / 100; // EMI formula: [P x r x (1+r)^n] / [(1+r)^n-1] $emi = ($loan_amount * $monthly_rate * pow(1 + $monthly_rate, $loan_tenure)) / (pow(1 + $monthly_rate, $loan_tenure) - 1); // Round off EMI value to 2 decimal places $emi = round($emi, 2); // Display the result echo "<div class='result'>"; echo "<p><strong>EMI Amount:</strong> $emi per month</p>"; echo "</div>"; } } ?> </div> </body> </html>
2. How the Loan EMI Calculator Works
- Input:
- Users enter the loan amount, annual interest rate, and loan tenure (in months).
- Processing:
- The formula for calculating EMI is:
[
EMI = \frac{P \times r \times (1 + r)^n}{(1 + r)^n – 1}
]
Where:- P = Loan Amount
- r = Monthly Interest Rate (annual rate divided by 12)
- n = Loan Tenure (in months)
- Output:
- The EMI is calculated and displayed as a rounded value with two decimal points, representing the monthly payment.
3. Integrating the Loan EMI Calculator into WordPress
Method 1: Creating a Custom Plugin
Steps:
- Create a Plugin Folder:
- Go to
/wp-content/plugins/
and create a folder calledloan-emi-calculator
.
- Create the Plugin File:
- Inside the
loan-emi-calculator
folder, create a file namedloan-emi-calculator.php
. - Add the following PHP code:
<?php /* Plugin Name: Loan EMI Calculator Description: A simple tool to calculate loan EMI based on amount, interest rate, and tenure. Version: 1.0 Author: Your Name */ // Function to display the Loan EMI Calculator function loan_emi_calculator_shortcode() { ob_start(); // Start output buffering ?> <div class="container"> <h1>Loan EMI Calculator</h1> <p>Enter the loan amount, interest rate, and loan tenure to calculate the EMI.</p> <form method="post"> <label for="loan_amount">Loan Amount:</label> <input type="text" id="loan_amount" name="loan_amount" placeholder="Enter loan amount" required> <label for="interest_rate">Annual Interest Rate (%):</label> <input type="text" id="interest_rate" name="interest_rate" placeholder="Enter interest rate" required> <label for="loan_tenure">Loan Tenure (in months):</label> <input type="text" id="loan_tenure" name="loan_tenure" placeholder="Enter loan tenure in months" required> <input type="submit" name="calculate_emi" value="Calculate EMI"> </form> <?php if (isset($_POST['calculate_emi'])) { $loan_amount = $_POST['loan_amount']; $interest_rate = $_POST['interest_rate']; $loan_tenure = $_POST['loan_tenure']; // Validate input if (!is_numeric($loan_amount) || !is_numeric($interest_rate) || !is_numeric($loan_tenure)) { echo "<div class='error'>Please enter valid numeric values.</div>"; } elseif ($loan_amount <= 0 || $interest_rate <= 0 || $loan_tenure <= 0) { echo "<div class='error'>All values must be greater than zero.</div>"; } else { // Convert interest rate to monthly rate $monthly_rate = ($interest_rate / 12) / 100; // EMI formula: [P x r x (1+r)^n] / [(1+r)^n-1] $emi = ($loan_amount * $monthly_rate * pow(1 + $monthly_rate, $loan_tenure)) / (pow(1 + $monthly_rate, $loan_tenure) - 1); // Round off EMI value to 2 decimal places $emi = round($emi, 2); // Display the result echo "<div class='result'>"; echo "<p><strong>EMI Amount:</strong> $emi per month</p>"; echo "</div>"; } } ?> </div> <?php return ob_get_clean(); // Return the output } // Register the shortcode [loan_emi_calculator] add_shortcode('loan_emi_calculator', 'loan_emi_calculator_shortcode'); ?>
- Activate the Plugin:
- Go to the WordPress Admin Dashboard > Plugins and activate the Loan EMI Calculator plugin.
- Add the Shortcode:
- To display the tool on any post or page, use the shortcode:
[loan_emi_calculator]
This Loan EMI Calculator Tool allows users to easily calculate their loan EMIs based on the input parameters.