Practical of Php
Practical of Php
Practical of Php
1.While loop
Code:
<?php
$x=1;
while($x<=5)
$x++;
?>
Output:
2.Do-while Loop
Code:
<?php
$x=5;
do
$x--;
while($x>=1);
?>
Output:
3. For loop
Code:
<?php
?>
Output:
Practical No. 2
Aim: Write a program in PHP to demonstrate conditional statement in PHP.
1.IF Condition
Code:
<?php
$x=07;
if($x=07)
?>
Output:
2.If-else Condition
Code:
<?php
$x=8;
if($x%2==0)
else
?>
Output:
3.Else-if Condition.
Code:
<?php
$grade = 85;
} else {
?>
Output:
Practical No. 3
Aim: Write a program in PHP to Create an Array, Insert elements in Array,
Accessing Elements from Array and Displaying elements of Arrays.
Code:
<?php
$array = [];
$array[] = "Apple";
$array[] = "Banana";
$array[] = "Cherry";
$array[] = "Date";
echo"<br>";
?>
Output:
Practical No. 4
Aim: Write a program in PHP to demonstrate including multiple files
in PHP webpage.
Code:
<?php
include("for.php");
echo"<br>";
include("while.php");
echo"<br>";
include("dowhile.php");
echo"<br>";
include("condition.php");
echo"<br>";
include("ifelse.php");
echo"<br>";
echo"file is included";
echo"<br>";
?>
Output:
Practical No. 5
Code:
<?php
displayArea($Val1, $Val2);
?>
OUTPUT:
Practical No. 7
Aim: Write a program to demonstrate String Function.
Code:
<?php
echo strlen ("Hello world");
?>
Output:
Code:
<?php
echo str_word_count ("Hello World");
?>
OUTPUT:
3. Reverse a String.
Code:
<?php
echo strrev ("MS Dhoni");
?>
OUTPUT:
Code:
<?php
echo strpos ("Kabhi kabhi lagta hai apan hi bhagwan hai","bhagwan");
?>
OUTPUT:
5. Replace text within a String.
Code:
<?php
echo str_replace ("Bhai","Sir","GM Bhai");
?>
OUTPUT: