PHP Lab Manual
PHP Lab Manual
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP
page</h1>
<?php
$string = "Hello World
<br> ";
echo $string;
print $string;
printf("%s", $string);
?>
</body>
</html>
!DOCTYPE html>
<html>
<body>
<h1>
<?php
$string = "Hello World ";
echo $string;
//print $string;
//printf("%s", $string);
?>
</h1>
</body>
</html>
2 Write a PHPscript to find odd or even number from given number.
<html>
<body>
<form method="post">
Enter a number:
</form>
</body>
</html>
<?php
if($_POST){
$number = $_POST['number'];
//if the reminder is 0 then the number is even otherwise the number is odd
if(($number % 2) == 0){
}else{
?>
$number1 = 12;
$number2 = 7;
$number3 = 15;
?>
Or
<?php
$number1 = 12;
$number2 = 7;
$number3 = 15;
?>
4 Write a PHPscript to swap two numbers.
i. Using a third variable
1. <?php
2. $a = 45;
3. $b = 78;
4. // Swapping Logic
5. $third = $a;
6. $a = $b;
7. $b = $third;
8. echo "After swapping:<br><br>";
9. echo "a =".$a." b=".$b;
10. ?>
Or
1. <?php
2. $a=234;
3. $b=345;
4. //using arithmetic operations + and -
5. $a=$a+$b;
6. $b=$a-$b;
7. $a=$a-$b;
8. echo "Value of a: $a</br>";
9. echo "Value of b: $b</br>";
10. ?>
Or
1. <?php
2. $a=234;
3. $b=345;
4. // using arithmetic operations * and /
5. $a=$a*$b;
6. $b=$a/$b;
7. $a=$a/$b;
8. echo "Value of a: $a</br>";
9. echo "Value of b: $b</br>";
10. ?>
1. <?php
2. $num = 4;
3. $factorial = 1;
4. for ($x=$num; $x>=1; $x--)
5. {
6. $factorial = $factorial * $x;
7. }
8. echo "Factorial of $num is $factorial";
9. ?>
Or
1. <html>
2. <head>
3. <title>Factorial Program using loop in PHP</title>
4. </head>
5. <body>
6. <form method="post">
7. Enter the Number:<br>
8. <input type="number" name="number" id="number">
9. <input type="submit" name="submit" value="Submit" />
10. </form>
11. <?php
12. if($_POST){
13. $fact = 1;
14. //getting value from input text box 'number'
15. $number = $_POST['number'];
16. echo "Factorial of $number:<br><br>";
17. //start loop
18. for ($i = 1; $i <= $number; $i++){
19. $fact = $fact * $i;
20. }
21. echo $fact . "<br>";
22. }
23. ?>
24. </body>
25. </html>
7 Write a PHP script to reverse a given number and calculate its sum
8 Write a PHP script to to generate a Fibonacci series using Recursive function
9 Write a PHP script to implement atleast seven string functions.
10 Write a PHP program to insert new item in array on any position in PHP.