Ex - No.10A Simple PHP Programs: Program
Ex - No.10A Simple PHP Programs: Program
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
OUTPUT:
If elseif else
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>
OUTPUT:
Switch
<html>
<body>
<?php
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?></body></html>
OUTPUT:
While loop
<html>
<body>
<?php
$i=1;
while($i<=5)
{
echo "The number is " . $i . "<br />";
$i++;
}
?>
</body>
</html>
OUTPUT:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Do while
<html>
<body>
<?php
$i=1;
do
{
$i++;
echo "The number is " . $i . "<br />";
}
while ($i<=5);
?>
</body>
</html>
OUTPUT:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
For Loop
<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
{
echo "The number is " . $i . "<br />";
}
?>
</body>
</html>
Output:
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
Foreach loop
<html>
<body>
<?php
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br />";
}
?>
</body>
OUTPUT:
one
two
three
Form.php
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
Welcome.php
<html>
<body>
</body>
</html>
OUTPUT: