Seema
Seema
Output:
Practical-2
Aim: - Write a PHP Program on Local and Global Variables.
<html>
<body>
<?php
$x=44; // global scope
function sampledemo()
{
global $x;
$y=59; // local scope
echo "Local Variable y is: $y <br>";
echo "Global Variable x is: $x";
}
sampledemo();// Function call
?>
</body>
</html>
Output:
function staticdemo()
{
$a=10;
static $b=20;
$a=$a+1;
$b=$b+1;
staticdemo();
staticdemo();
staticdemo();
staticdemo();
?>
</body>
</html>
Output:
Practical - 4
Aim: Write a PHP program to find odd or even number from given number.
<Html>
<Head> <Title> Find out odd or even number. . ! </title>
</Head >
<body>
Practical - 5
Aim: Write a PHP program to find maximum of three numbers using else if.
<html>
<head>
<title> Max of three numbers </title>
</head>
<body>
<?php
// Demo on if else
$a=10;
$b=20;
$c=30;
if($a>$b && $a>$c)
echo "A is Biggest Number";
else if($b>$a && $b>$c)
echo "B is Biggest Number";
else
echo "C is Biggest Number";
?>
</body>
</html>
Output:
}
}
?>
</body>
</html>
Output:
Practical - 7
Aim: Write a PHP program to perform arithmetic operations using switch case.
<html>
<body>
<?php
$a=10;
$b=20;
$choice=1;
switch($choice)
{
case 1:
$c=$a+$b;
echo "the addition is:".$c;
break;
case 2:
$c=$a-$b;
echo "the subtraction is:".$c;
break;
case 3:
$c=$a*$b;
Output:
Practical - 8
Aim: Write a PHP program to swap two numbers.
<html> <head>
<title> Swapping of two numbers. . ! </title>
</head>
<body>
<?php
$a = 10;
$b = 20;
echo "a = $a"."<br>"."b = $b"."<br>";
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
echo "<b>After Swapping"."<br>"." a = $a"."<br>"."b = $b<b>";
?>
</body>
</html>
Output:
Practical - 9
Aim: Write a PHP Program to display the Fibonacci series using while loop.
<html>
<body>
<?php
$a=0;
?>
</body>
</html>
Output:
Practical - 10
Aim: Write a PHP Program to display the sum of “N” natural numbers using do while loop.
<html><body>
<?php
$n=10;
$sum=0;
$i=1;
while($i<=$n)
{
$sum=$sum+$i;
$i++;
}
echo "<b>The sum of $n Natural Numbers are:".$sum;
?>
</body></html>
Output:
Output:
Practical - 12
Aim: Write a PHP Program to display the text using Function.
<html>
<head><title> Deno on Functions in PHP</title></head>
<body> <?php
function DisplayText()
{
echo "<b>Hello this is Seshu from TJPS College";
}
DisplayText(); //calling function
?>
</body>
</html>
Output:
Output:
Practical - 14
Aim: Write a PHP Program to pass Multiple Arguments in Function.
<html>
<head><title> Demo on Functions in PHP</title>
</head>
<body>
<?php
function MultipleArguments($name,$age)
{
echo "Hello $name, you are $age years old<br/>";
}
MultipleArguments ("Murali Sir",50);
MultipleArguments ("Mark Sir",45);
MultipleArguments ("Seshu",35);
?>
</body>
</html>
Output:
Practical - 16
Aim: Write a PHP Program to Perform String Operations.
<html><body>
<?php
$str='Hello we are from TJPS College Students';
echo $str;
$str="<br>Hello we are from TJPS College Students ";
echo $str;
echo "<br>";
echo "The length of the string is:";
echo $len=strlen("Hello this is Seshu");
echo "<br>";
echo "The length of the word is:";
echo str_word_count("Hello this is Seshu");
echo "<br>";
echo "The reverse of the string is:";
echo strrev("Hello world");
echo "<br>";
echo "The position of the string is:";
echo strpos("Hello world!", "world");
echo "<br>";
echo "The replace of the string is:";
echo str_replace("world","Seshu","Hello world!");
echo "<br>";
$str="Hello friends i am SESHU";
$str=strtolower($str);
echo "$str";
echo "<br>";
$str="Hello friends i am Mohan";
$str=strtoupper($str);
echo "$str";
?></body></html>
Practical - 17
Aim: Write a PHP Program to Create Student Registration Form.
<b>Gender:
<input type="radio" name="Gender:"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Others<br><br><br>
<center>
<a href="submission.html"><input type="button" name="Ok"
value="Submit"></a>
<input type="button" name="Ok" value="Cancel">
Output 2:
Practical - 18
Aim: Write a PHP Program to Create Employee Registration Form.
<center><h1> @@@@ Employee Registration Form @@@@ </h1></center>
<b>Name of the Employee: <input type="text" name="name" value=""><br><br>
<b>Father Name: <input type="text" name="email" value=""><br><br>
<b>Gender:
<input type="radio" name="Gender:"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Others<br><br>
<b>Date of Join: <input type="text" name="website" value=""><br><br>
<b>Date of Birth: <input type="text" name="website" value=""><br><br>
<b>Designation: <input type="text" name="website" value=""><br><br>
<b>Email: <input type="text" name="website" value=""><br><br>
<b>Phone Number: <input type="text" name="website" value=""><br><br>
<center>
<a href="submission.html"><input type="button" name="Ok"
value="Submit"></a>
<input type="button" name="Ok" value="Cancel">
Output 1:
Output 2:
Practical - 19
Aim: Write a PHP Program on Form Validations.
<!DOCTYPE html>
<html>
<head>
<style>
.error {color: #FF0001;}
</style> </head> <body>
//String Validation
if (emptyempty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = input_data($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only alphabets and white space are allowed";
}
}
//Email Validation
if (emptyempty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = input_data($_POST["email"]);
// check that the e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
//Number Validation
if (emptyempty($_POST["mobileno"])) {
$mobilenoErr = "Mobile no is required";
} else {
$mobileno = input_data($_POST["mobileno"]);
// check if mobile no is well-formed
if (!preg_match ("/^[0-9]*$/", $mobileno) ) {
$mobilenoErr = "Only numeric value is allowed.";
}
//check mobile no length should not be less and greator than 10
if (strlen ($mobileno) != 10) {
$mobilenoErr = "Mobile no must contain 10 digits.";
}
}
//URL Validation
if (emptyempty($_POST["website"])) {
$website = "";
} else {
//Checkbox Validation
if (!isset($_POST['agree'])){
$agreeErr = "Accept terms of services before submit.";
} else {
$agree = input_data($_POST["agree"]);
}
}
function input_data($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<center><h1>***** Validations in PHP *****</h1> </center>
<span class = "error">* Required field </span>
<br><br>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>" >
Name:
<input type="text" name="name">
<span class="error">* <?php echo $nameErr; ?> </span>
<br><br>
E-mail:
<input type="text" name="email">
<span class="error">* <?php echo $emailErr; ?> </span>
<br><br>
Mobile No:
<input type="text" name="mobileno">
<span class="error">* <?php echo $mobilenoErr; ?> </span>
<br><br>
Website:
<input type="text" name="website">
<span class="error"><?php echo $websiteErr; ?> </span>
<br><br>
<?php
if(isset($_POST['submit'])) {
if($nameErr == "" && $emailErr == "" && $mobilenoErr == "" && $genderErr ==
"" && $websiteErr == "" && $agreeErr == "") {
echo "<h3 color = #FF0001> <b>You have sucessfully registered.</b>
</h3>";
echo "<h2>Your Input:</h2>";
echo "Name: " .$name;
echo "<br>";
echo "Email: " .$email;
echo "<br>";
echo "Mobile No: " .$mobileno;
echo "<br>";
echo "Website: " .$website;
echo "<br>";
echo "Gender: " .$gender;
} else {
echo "<h3> <b>You didn't filled up the form correctly.</b> </h3>";
}
}
?>
</body> </html>
Output:
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
Output: