0% found this document useful (0 votes)
23 views

Ex - No.10A Simple PHP Programs: Program

The document provides examples of basic PHP programs that demonstrate different PHP features including: 1) Printing text using echo and PHP tags; 2) Conditional statements like if/elseif/else and switch statements; 3) Looping structures like while, do-while, for, and foreach loops; 4) Handling HTML forms with PHP by submitting to another PHP file.

Uploaded by

Durga Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Ex - No.10A Simple PHP Programs: Program

The document provides examples of basic PHP programs that demonstrate different PHP features including: 1) Printing text using echo and PHP tags; 2) Conditional statements like if/elseif/else and switch statements; 3) Looping structures like while, do-while, for, and foreach loops; 4) Handling HTML forms with PHP by submitting to another PHP file.

Uploaded by

Durga Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EX.NO.

10a SIMPLE PHP PROGRAMS


PROGRAM:

<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
OUTPUT:

Php using conditional statements


If statement
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!";
?>
</body>
</html>
If else
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</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:

Php program using loops

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

Program for php form handling

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>

Welcome <?php echo $_POST["fname"]; ?>!<br />


You are <?php echo $_POST["age"]; ?> years old.

</body>
</html>

OUTPUT:

You might also like