0% found this document useful (0 votes)
10 views35 pages

Iwd Word File

The document outlines practical exercises for installing and configuring PHP, a web server, and MySQL database using XAMPP/WAMP/LAMP/MAMP, as well as creating simple web applications. It includes steps for installation, HTML and PHP code examples for a 'Hello World' page, a calculator, car company lookup, Fibonacci series, multiplication tables, string manipulation, and Morse code encoding. Each practical exercise is accompanied by code snippets and expected outputs.

Uploaded by

aaravmehta2403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views35 pages

Iwd Word File

The document outlines practical exercises for installing and configuring PHP, a web server, and MySQL database using XAMPP/WAMP/LAMP/MAMP, as well as creating simple web applications. It includes steps for installation, HTML and PHP code examples for a 'Hello World' page, a calculator, car company lookup, Fibonacci series, multiplication tables, string manipulation, and Morse code encoding. Each practical exercise is accompanied by code snippets and expected outputs.

Uploaded by

aaravmehta2403
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Practical 1(A)

Aim: Install and configure PHP, Web Server and MySQL database using
XAMPP/WAMP/LAMP/MAMP.
 Steps To Install Xampp Server in Computer

Step 1: Search in Google

Step 2 : Select File

Page | 1
Step 3: After Download Install Xampp in Computer

Step 4: Select Components

Page | 2
Step 5: Set The Path

Step 6: Select Language

Step 7: Click Next To Install Xampp


Page | 3
Step 8: Installing Process

Step 9: After Installation Click Finish

Page | 4
Step 10: Open Xampp Control Panel

Page | 5
Practical 1(B)
Aim: Create a web page that displays “Hello World.”
Code:
<html>
<head>
<title>practical 1</title>
</head>
<body>
<?php
echo "hello world";
?>
</body>
</html>

Output:

Page | 6
Practical 2
AIM:-Write a script to implement a simple calculator for mathematical operations.
 HTML CODE:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PRACTICAL-2(A)</title>
<style>
body{
text-align: center;
font-weight: 700;
}
form{
margin-top: 70px;
font-size: 30px;

}
</style>
</head>
<body>
<h1><b>CALCULATOR</b></h1>
<hr>
<form method="post" action="Practical2(A).php">
<label>Enter 1st Number</label>
<input type="number" placeholder="Enter number" name="number1">
<br><br>
<label>SELECT OPTION</label>
<select name="Operators">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<br><br>
<label>Enter 2nd Number</label>
<input type="number" placeholder="Enter number" name="number2">
<br><br>
<input type="submit" name="SUBMIT">
</form>
</body>
</html>

 PHP CODE:-
<?php

Page | 7
$a = $_POST['number1'];
$b = $_POST['number2'];
$operator = $_POST['Operators'];
if($operator == '+')
{
$sum=$a+$b;
echo "Addition is :".$sum;
}
elseif($operator == '-')
{
$sub=$a-$b;
echo "Substraction is :".$sub;
}
elseif($operator == '*')
{
$mul=$a*$b;
echo "Multiplication is :".$mul;
}
elseif($operator == '/')
{
if($b==0)
{
echo "not divisible";
}
else{
$div=$a/$b;
echo "Division is :".$div;
}
}
?>
 OUTPUT:-

Page | 8
Practical:-3(A)
AIM:- Write a script that reads the name of the car and displays the name of the company the
car belongs to as per the below table:

Code:-
<!DOCTYPE html>
<html>
<head>
<title>Practical 3(A)</title>
</head>
<body>
<form method="post">
<label for="carName">Enter Car Name:</label>
<input type="text" id="carName" name="carName">
<input type="submit" value="Lookup">
</form>

<?php
if (isset($_POST['carName']))
{
$carName = $_POST['carName'];
Page | 9
$carCompanies = array
(
"Tata" => array("Safari", "Nexon", "Tigor", "Tiago"),
"Mahindra" => array("XUV300", "XUV500", "XUV700"),
"Hyundai" => array("i10", "i20", "Venue", "Creta"),
"Suzuki" => array("Swift", "wagenar", "Baleno", "Brezza")
);
foreach ($carCompanies as $company => $models)
{
if (in_array($carName, $models))
{
echo "<p>The $carName belongs to $company.</p>";
break;
}
}
if (!in_array($carName, array_merge(...array_values($carCompanies))))
{
echo "<p>No company was found for $carName.</p>";
}
}
?>
</body>
</html>
Output:-

Page | 10
Page | 11
Practical:-3(B)
AIM:- Write a script to display Fibonacci numbers up to a given term.
Code:-
<html>
<body>
<form method="POST">
<lable for='term'>Enter the number:</lable>
<input type="number" id="term" name="term"><br><br>
<button type="submit">Generate:</button>
</form>

<?php
if(isset ($_POST['term']))
{
$term=$_POST['term'];
$n1=0;
$n2=1;
echo "<p>Fibonacci Series:</p>";
echo "<ul>";
echo "<li> $n1 </li>";
Page | 12
echo "<li> $n2 </li>";
for($i=3 ; $i<=$term ; $i++)
{
$sum=$n1+$n2;
echo "<li> $sum </li>";
$n1=$n2;
$n2=$sum;
}
echo "</ul>";
}
?>
</body>
</html>
Output:-

Page | 13
Practical:-3(C)
AIM:- Write a script to display a multiplication table for the given number.
HTML Code:-
<html>
<head>
<title>Multiplication Table </title>
</head>
<body>

<form method="post" action="pr3(C).php">


<label for="num">Enter the Number:</label>
<input type="text" name="num" id="num">
<button type="submit">Generate Tabel</button>
Page | 14
</form>
</body>
</html>
PHP Code:-
<?php
if (isset($_POST['num']))
{
$num=$_POST['num'];
echo "<h3> Multiplication table of . $num </h3>" ;

for ($i=1; $i<=10; $i++)


{
echo "<table border='0' >";
echo"<tr><td>". $num . "X " .$i . "=</td><td>" .($num*$i) . "</td></tr>";
echo"</table>";
}
}?>
</body>
</html>
Output:-

Page | 15
Page | 16
Practical:-4(A)
AIM:-Write a script to calculate the length of a string and count the number of words in the
given string without using string functions.
CODE:-
<!DOCTYPE html>
<html>
<body>
<?php
$string = 'Yug Sondagar';
$length = 0;
$wordcount = 1;
while (isset($string[$length]))
{
$length++;
}
for ($i = 0; $i < $length; $i++)
{
if ($string[$i] == ' ')
{
$wordcount++;
}
}
echo "The String = \"$string\".<br><br>";
echo "The length of the string: $length.<br><br>";
echo "The total number of words in the string: $wordcount.<br><br>";
?>
</body>
</html>

Page | 17
OUTPUT:-

Page | 18
Practical:-4(B)
AIM:- Write a script to sort a given indexed array.
CODE:-
<html>
<body>
<?php
$number =array (0,9,8,2,1);
echo"Original: ";
print_r($number);
echo "<br> <br>";
for ($i=0;$i<=count($number);$i++)
{
for ($j=$i+1; $j<count($number); $j++)
{
if($number[$i] > $number[$j])
{
$temp=$number[$i];
$number[$i]=$number[$j];
$number[$j]=$temp;
}
}
}
echo"Sorted: ";
print_r($number);
?>
</body>
</html>

Page | 19
OUTPUT:-

Page | 20
Practical:-4(C)
AIM:- Write a script to perform 3 x 3 matrix Multiplication.
CODE:-
<html>
<?php
$a = array
(
array(1, 0, 8),
array(0, 2, 1),
array(1, 3, 2)
);
$b = array
(
array(1, 0, 1),
array(2, 3, 1),
array(1, 4, 0)
);
$resultant=array();
echo"<h3><br>Array A<br></h3>";
for($i=0;$i<3;$i++)
{
for($j=0;$j<3;$j++)
{
echo"\t".$a[$i][$j];
}
echo"<br>";
}
echo"<h3><br>Array B<br></h3>";
for($i=0;$i<3;$i++)
{
for($j=0;$j<3;$j++)
{

Page | 21
echo"\t".$b[$i][$j];
}
echo"<br>";
}
for($i=0;$i<3;$i++)
{
for($j=0;$j<3;$j++)
{
$resultant[$i][$j]=$a[$i][$j]*$b[$i][$j];
}
}
echo"<h3><br>Resultant Matrix<br></h3>";
for($i=0;$i<3;$i++)
{
for($j=0;$j<3;$j++)
{
echo"\t".$resultant[$i][$j];
}
echo"<br>";
}
?>
</body>
</html>

OUTPUT:-

Page | 22
Page | 23
Practical:-4(D)
AIM:- Write a script to encode a given message into equivalent Morse code.
CODE:-
<!DOCTYPE html>
<html>
<body>
<h1>Morse Code Encoder</h1>
<form method="post">
<label for="message">Enter String to Encode : </label>
<input type="text" name="message" id="message">
<input type="submit" value="Encode">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$morse_alphabet = array

(
'a' => '.-',
'b' => '-...',
'c' => '-.-.',
'd' => '-..',
'e' => '.',
'f' => '..-.',
'g' => '--.',
'h' => '....',
'i' => '..',
'j' => '.---',
'k' => '-.-',
'l' => '.-..',
'm' => '--',
'n' => '-.',

Page | 24
'o' => '---',
'p' => '.--.',
'q' => '--.-',
'r' => '.-.',
's' => '...',
't' => '-',
'u' => '..-',
'v' => '...-',
'w' => '.--',
'x' => '-..-',
'y' => '-.--',
'z' => '--..',
'1' => '.----',
'2' => '..---',
'3' => '...--',
'4' => '....-',
'5' => '.....',
'6' => '-....',
'7' => '--...',
'8' => '---..',
'9' => '----.',
'0' => '-----'
);

$message = $_POST["message"];

$message_chars = str_split(strtolower($message));

$morse_code = "";
foreach ($message_chars as $char)
{
if (array_key_exists($char, $morse_alphabet))

Page | 25
{
$morse_code .= $morse_alphabet[$char] . " ";
}
else
{
$morse_code .= "/ ";
}
}
echo "<p>Encoded Message:</p>";
echo "<p>$morse_code</p>";
}
?>
</body>
</html>
OUTPUT:-

Page | 26
Practical:-5(A)
AIM:- Write scripts using string functions:
a)to check if the given string is lowercase or not.
b)to reverse the given string.
c)to remove white spaces from the given string.
d)to replace the given word from the given string.
CODE:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Function</title>
<h1>String Function</h1><br>
<form method="post"><label for="string">Enter the string:</label>
<input name="string" type="text">
<br>
<button type="submit" name="string_lowercase">Lowercase</button>
<button type="submit" name="string_reverse">Reverse</button>
<button type="submit" name="string_space">Space</button>
<button type="submit" name="string_replace">Replace</button>
<br>
</form>
</head>
<body>
<?php
if(isset($_POST['string']))
$string = $_POST['string'];
{
if(isset($_POST['string_lowercase']))
{
Page | 27
if(ctype_lower($string))
{
echo "The string is in Lowercase.";
}
else{
echo "The string is in Uppercase.";
}
}
elseif(isset($_POST['string_reverse']))
{
$reverse_string = strrev($string);
echo "The reveresed string is $reverse_string";
}
elseif(isset($_POST['string_space']))
{
$remove_space = str_replace(" ","",$string);
echo "The string without space is : $remove_space";
}
elseif(isset($_POST['string_replace']))
{
$replace_string = str_replace("Aa","A",$string);
echo "The new string is $replace_string ";
}
}
?>
</body>
</html>

OUTPUT:-

Page | 28
Page | 29
Page | 30
Practical:-5(B)
AIM:- Write scripts using math functions:
a) to generate a random number between the given range.
B) to display the binary, octal and hexadecimal of a given decimal number.
C) to display the sin, cos and tan of the given angle.
CODE:-
<html>
<body>
<hr>
<h3>Generate Random Number Between Given Range</h3>
<form method="Post">
<lable>Enter The Starting Number: </lable>
<input type = "number" name = "range1" id = "number"></br></br>
<lable for="range2">Enter The Ending Number: </lable>
<input type = "number" name = "range2" id = "number"></br></br>
<button type= "submit">Generate</button>
</form>
<hr>
<h3>Display the Binary ,Octal and Hexadecimal of given Decimal Number</h3>
<form method = "post">
<lable for="Dec">Enter The Decimal Number: </lable>
<input type = "number" name = "Dec" id = "Dec"></br></br>
<button type= "submit" value="Binary, Octal, Hexadecimal" name ="number">Generate</button>
</form>
<hr>
<h3>Display sin, cos and tan of given angle</h3>
<form method = "post">
<lable for="Ang">Enter The Angle: </lable>
<input type = "number" name = "Ang" id = "number"></br></br>
<button type= "submit" value="Sin, Cos, Tan" name ="number">Generate</button>
<hr>
Page | 31
<?php
if(isset($_POST['range1']) && isset($_POST['range2']))
{
$range1 = $_POST['range1'];
$range2 = $_POST['range2'];
$random_number = rand($range1,$range2);

echo "The random number is : $random_number";


}
if(isset($_POST['Dec']))
{
$Dec = $_POST['Dec'];
$binary = decbin($Dec);
$octal = decoct($Dec);
$hexa = dechex($Dec);

echo "The binary number is $Dec : $binary"."<br>";


echo "The octal number is $Dec : $octal"."<br>";
echo "The hexadecimal number is $Dec : $hexa"."<br>";
}
if(isset($_POST['Ang']))
{
$Ang=$_POST['Ang'];
$sin = sin(deg2rad("$Ang"));
$cos = cos(deg2rad("$Ang"));
$tan = tan(deg2rad("$Ang"));

echo "The sin value is : $sin"."<br>";


echo "The cos value is : $cos"."<br>";
echo "The tan value is : $tan"."<br>";
}
?>

Page | 32
</body></html>
OUTPUT:-

Page | 33
Page | 34
Page | 35

You might also like