Question:
. Create a PHP file to print any text using variable
Code:
<html>
<head>
<?php
$variable="Hello World";
echo "<center><h1>".$variable."</h1></center>";
?>
<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px;">This is a Simple Example To Show Text Using Variable in PHP</p>
</body>
</html>
Output:
Question:
Demonstrate the use of statements, operators and functions in PHP.
Code:
<html>
<head>
<?php
if(isset($_POST['c'])){
$a=$_POST['a'];
$b=$_POST['b'];
$d=$_POST['d'];
operate($a,$b,$d);
}
function operate($a,$b,$d)
{
if(!(empty($a)||empty($b))){
if($d=="Add"){
echo "<html><h1>Result is : ".($a+$b)."</h1></html>";
}
else if($d=="Subtract"){
echo "<html><h1>Result is : ".($a-$b)."</h1></html>";
}
else if($d=="Multiply"){
echo "<html><h1>Result is : ".($a*$b)."</h1></html>";
}
else if($d=="Modulus"){
echo "<html><h1>Result is : ".($a%$b)."</h1></html>";
}
}else{
echo "All Fields are Mandatory";
}
}
?>
<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of statements, operators and functions in PHP</p>
<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter A : ">
<input type="number" name="b" placeholder="Enter B : ">
<select name="d">
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Modulus</option>
</select>
<input type="submit" value="Submit" name="c">
</form>
</center>
</body>
</html>
Output:
Question:
Demonstrate the use of Loops and arrays in PHP
Code:
<html>
<head>
<?php
if(isset($_POST['c']))
{
$array=array();
$a=$_POST['a'];
for($i=1;$i<=10;$i++){
$array[$i]=$a*$i;
// echo $a." * ".$i." = ".($a*$i);
}
for($i=1;$i<=10;$i++){
echo "<h1>",$a." * ".$i." = ".$array[$i]."</h1><br>";
}
}
?>
<style type="text/css">
h1{
color: white;
margin:1in;
margin-bottom: 0in;
margin-top: 0in;
text-align: center;
background-color: purple;
font-size: 30px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of Loops and arrays in PHP</p>
<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter Any Number : " required>
<input type="submit" value="Submit" name="c">
</form>
</center>
</body>
</html>
Output:
. Create a PHP file to print any text using variable
Code:
<html>
<head>
<?php
$variable="Hello World";
echo "<center><h1>".$variable."</h1></center>";
?>
<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px;">This is a Simple Example To Show Text Using Variable in PHP</p>
</body>
</html>
Output:
Question:
Demonstrate the use of statements, operators and functions in PHP.
Code:
<html>
<head>
<?php
if(isset($_POST['c'])){
$a=$_POST['a'];
$b=$_POST['b'];
$d=$_POST['d'];
operate($a,$b,$d);
}
function operate($a,$b,$d)
{
if(!(empty($a)||empty($b))){
if($d=="Add"){
echo "<html><h1>Result is : ".($a+$b)."</h1></html>";
}
else if($d=="Subtract"){
echo "<html><h1>Result is : ".($a-$b)."</h1></html>";
}
else if($d=="Multiply"){
echo "<html><h1>Result is : ".($a*$b)."</h1></html>";
}
else if($d=="Modulus"){
echo "<html><h1>Result is : ".($a%$b)."</h1></html>";
}
}else{
echo "All Fields are Mandatory";
}
}
?>
<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of statements, operators and functions in PHP</p>
<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter A : ">
<input type="number" name="b" placeholder="Enter B : ">
<select name="d">
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Modulus</option>
</select>
<input type="submit" value="Submit" name="c">
</form>
</center>
</body>
</html>
Output:
Question:
Demonstrate the use of Loops and arrays in PHP
Code:
<html>
<head>
<?php
if(isset($_POST['c']))
{
$array=array();
$a=$_POST['a'];
for($i=1;$i<=10;$i++){
$array[$i]=$a*$i;
// echo $a." * ".$i." = ".($a*$i);
}
for($i=1;$i<=10;$i++){
echo "<h1>",$a." * ".$i." = ".$array[$i]."</h1><br>";
}
}
?>
<style type="text/css">
h1{
color: white;
margin:1in;
margin-bottom: 0in;
margin-top: 0in;
text-align: center;
background-color: purple;
font-size: 30px;
font-family: Arial;
}
</style>
</head>
<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of Loops and arrays in PHP</p>
<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter Any Number : " required>
<input type="submit" value="Submit" name="c">
</form>
</center>
</body>
</html>
Output: