PHP P4
PHP P4
PAGE
S.NO. DATE NAME OF THE PROGRAM SIGNATURE
NO.
SIMPLE HTML FORM TO CREATE A
1
USERNAME
PHP SCRIPT TO REDIRECT A USER TO A
2
DIFFERENT PAGE
DATE:
AIM:
To write a simple HTML form and accept the username and display the name
through PHP echo statement.
ALGORITHM:
<head>
<title>Student Name</title>
</head>
<body>
<form method='post'>
</form>
<?php
$name=$_POST['name'];
echo"<h3>Hello $name</h3>";
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to accept the username and display the name through PHP
echo statement was executed and verified successfully.
EX NO: 02
DATE:
AIM:
ALGORITHM:
3. Open the body tag, inside the body tag open the PHP script.
<body>
<?php
header('Location:http://localhost:8080/ex01.php');
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to redirect a user to a different page was executed and
verified successfully.
EX.NO: 03
DATE:
AIM:
To write a PHP function to test whether a number is greater than 30, 20, 10
using ternary operator.
ALGORITHM:
2. Open the body tag, inside the body tag open the PHP script.
DATE:
AIM:
To write a PHP script which displays the capital and its country name from the
given array in a sorted array.
ALGORITHM:
2. Open the body tag,inside the body tag open the PHP script.
3. Create an array with variable $city for display the capital and country name.
<body>
<?php
$city =array("Newdelhi"=>"India","Pairs"=>"France",
"London"=> "UK","Washingtgon"=>"US",
"Colombo"=>"Srilannka","Beijing"=>"China",
"Tokyo"=>"Japan","kabul"=>"Afghanistan",
"Lusaka"=>"Zambia","Mascat"=>"Oman");
asort($city);
foreach($city as $capital=>$country)
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to display the capital and its name in a sorted form was
executed and verified successfully.
EX NO: 05
DATE:
AIM:
ALGORITHM:
6. Total is calculated.
DATE:
AIM:
To write a PHP script using ‘for’ loop to add all the integers between 0
and 30 and display the total.
ALGORITHM:
4. Initialize sum=0
6. If $x=0;-Initialize the loop counter ($x), and set the start value to 0.
<body>
<?php
$sum = 0;
$sum +=$x;
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to add all the integers between 0 and 30, and displaying its
total was executed and verified successfully.
EX NO: 07
DATE:
AIM:
To write a PHP script using for loop that creates a chess board.
ALGORITHM:
4. To create the chess in PHP two loops are needed and each will create 8
blocks.
5. The inner-loop will generate table row with black and white background-color
based on the value.
DATE:
AIM:
To write a PHP function that checks if a string is all lower case character or not.
ALGORITHM:
3. Open the body tag, inside the body tag open the PHP script.
6. If it is lowercase string then display the result, else display the result as not
in lowercase letters.
7. Stop.
PROGRAM :
<html>
<body>
<?php
$string = "india";
if (ctype_lower($string))
else
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to check the string contains all the characters are lowercase
or not.
EX NO:09
DATE:
DIFFERENCES BETWEEN TWO DATES
AIM:
ALGORITHM:
3. Open the body tag,inside the body tag open the PHP script.
<body>
<?php
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to calculate the differences between two date was executed
and verified successfully.
EX NO: 10
DATE:
AIM:
To write a PHP script to display times in a specified time zone.
ALGORITHM:
1. Start the program.
3. Open the body tag,inside the body tag open the PHP script.
4. Using the ini_set() function to find the timezone of given country and its
capital.
<body>
<?php
ini_set('date.timezone','America/New_York');
?>
</body>
</html>
OUTPUT:
RESULT:
Thus the program to display specified time in a zone was executed and verified
successfully.