PHP_exp1_62
PHP_exp1_62
- 1
Date of Submission:
Program Execution/
formation/ Timely
Viva Experiment
correction/ Submission Sign with Date
(03) Total (10)
ethical practices (01)
(06)
Experiment No. - 1
PHP Script to Perform Simple Arithmetic Operations and Display the Result
1.1 Aim:
To develop a PHP script that performs basic arithmetic operations (addition, subtraction,
multiplication, and division) and displays the results dynamically.
What is PHP? PHP (Hypertext Preprocessor) is a widely used open-source server-side scripting
language primarily designed for web development. It can be embedded within HTML and is
executed on the server to generate dynamic web pages.
Features of PHP:
Arithmetic Operations in PHP: PHP supports basic arithmetic operations, which include:
<?php
if(isset($_POST['calculate'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
echo "<h3>Results:</h3>";
echo "Addition: " . ($num1 + $num2) . "<br>";
echo "Subtraction: " . ($num1 - $num2) . "<br>";
echo "Multiplication: " . ($num1 * $num2) . "<br>";
if ($num2 != 0) {
echo "Division: " . ($num1 / $num2) . "<br>";
echo "Modulus: " . ($num1 % $num2) . "<br>";
} else {
echo "Cannot divide by zero.";
}
}
?>
</body>
</html>
1.7 Output:
1.8 Conclusion:
By implementing this PHP script, we have successfully demonstrated how to perform basic
arithmetic operations dynamically using user inputs. This experiment enhances our
understanding of PHP scripting, form handling, and server-side execution.