Professional Documents
Culture Documents
PHP 3-2
PHP 3-2
<html>
<body>
<CENTER><table border="2"cellpadding="2"></CENTER>
<?php
$row=3;
$col=3;
$arr=array(
array(10,11,14),
array(10,21,11),
array(10,22,11));
for($i=0;$i<$row; $i++)
echo"<tr><td>rows".$i;
$rsum=0;
for($j=0;$j<$col;$j++)
echo"<td>".$arr[$i][$j];
$rsum=$rsum+$arr[$i][$j];
echo"<td><b>".$rsum."</tr></b>";
echo"<tr><th>column sum";
for($j=0;$j<$col;$j++)
$csum=0;
for($i=0;$i<$row;$i++)
$csum=$csum+$arr[$i][$j];
}
echo"<td><b>".$csum."</b>";
echo"</tr>";
?>
</table>
</body>
</html>
OUTPUT
FACTORIAL IN PHP
<html>
<head>
</head>
</form>
<?php
$number=$_POST["num"];
echo"<br>";
$fact = 1;
for($i=1;$i<=$number;$i++)
$fact = $fact*$i;
?>
</body>
</html>
OUTPUT
MULTIPLICATION IN PHP
<html>
<head>
</head>
<center>
</form>
<?php
$number=$_POST["num"];
$range=$_POST["ran"];
echo"<br>";
for($i=1;$i<=$range; $i++)
echo $number."*".$i."=".$number*$i."<br>";
?>
</body>
</html>
OUTPUT
WORD TO DIGIT
<HTML>
<HEAD>
</title>
</head>
<br><br><br><center><br><br><br>
</form>
<?php
$words =$_POST["numw"];
$dig=' ';
$wdlow=strtolower($words );
$wdarray=explode(" ",$wdlow);
switch (trim($wrds))
case'one' :$dig.='1';break ;
?>
</body>
</html>
OUTPUT
SUM OF FIRST N PRIME NUMBERS
<html>
<head>
</head>
<form method="POST">
</form>
<?php
$n=$_POST["num"];
$ct = 0 ;
$i = 3;
$c = 0;
$sum =0;
if($n>1)
$sum=$sum + 2;
for($ct =2;$ct<=$n;$i++)
for($c=2;$c<$i;$c++)
if($i%$c==0)
break;
if($c==$i)
echo"<br>".$i;
$sum =$sum+$i;
$ct++;
else
?>
</body>
</html>
OUTPUT
Colourise first character
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
$characters = mb_str_split($word);
$firstCharacter = array_shift($characters);
return $result;
$word = "BORDER"; // Replace this with the word you want to modify
?>
</body>
</html>
OUTPUT
Reverse and write file
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
$content = file_get_contents($inputFileName);
$reversedContent = strrev($content);
echo "File has been successfully reversed and written to: $outputFileName\n";
$inputFile = "helo.txt";
$outputFile = "hello.txt";
reverseAndWriteToFile($inputFile, $outputFile);
?>
</body>
</html>
OUTPUT
E-mail verification
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>E-MAIL VALIDATION</title>
</head>
<body>
<?php
function isValidEmail($email) {
$email1 = "user@example.com";
$email2 = "invalid_email";
if (isValidEmail($email1)) {
} else {
if (isValidEmail($email2)) {
} else {
?>
</body>
</html>
OUTPUT
RENAME TXT TO XTX
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
function renameTxtToXtx()
$files = glob("*.txt");
if (rename($file, $newName)) {
} else {
renameTxtToXtx();
?>
</body>
</html>
OUTPUT
PERFORM TASK WITH DELAY
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
function performTaskWithDelay($seconds)
sleep($seconds);
performTaskWithDelay($delayInSeconds);
?>
</body>
</html>
OUTPUT
Read and print the E-mail address from xml document
<!DOCTYPE html>
<html>
<body>
<?php
$myXMLData =
<note>
<to>Tove</to>
<from>Jani</from>
<body>smkc@gmail.com</body>
<body>smkc1@yahoo.com</body>
<body>deptofcs@gmail.com</body>
<body>deptofcs@yahoo.com</body>
</note>";
print_r($xml);
?>
</body>
</html>
OUTPUT
Student marksheet operations
Sd.php
<html>
<table>
<tr> <td> College Name </td> <td> <input type=text name=cname size=30> </td> </tr>
<tr> <td> Student Name </td> <td> <input type=text name=sname size=30> </td> </tr>
<tr> <td> Father Name </td> <td> <input type=text name=fname size=30> </td> </tr>
<tr> <td> DOB </td> <td> <input type=text name=dob size=30> </td> </tr>
<tr>
<td>
</td>
</tr>
<tr> <td> Hindi Marks </td> <td> <input type=text name=hin size=30> </td> </tr>
<tr> <td> English Marks </td> <td> <input type=text name=eng size=30> </td> </tr>
<tr> <td> Maths Marks </td> <td> <input type=text name=mat size=30> </td> </tr>
<tr> <td> Physics Marks </td> <td> <input type=text name=phy size=30> </td> </tr>
<tr> <td> Chemistry Marks </td> <td> <input type=text name=che size=30> </td> </tr>
<tr> <td> <input type=submit> <td> <td> <input type=reset> </td> </tr>
</table>
</form>
</html>
Res.php
<html>
<?php
$cname=$_GET['cname'];
$sname=$_GET['sname'];
$fname=$_GET['fname'];
$dob=$_GET['dob'];
$gen=$_GET['gen'];
$hin=$_GET['hin'];
$eng=$_GET['eng'];
$mat=$_GET['mat'];
$phy=$_GET['phy'];
$che=$_GET['che'];
$total=$hin+$eng+$mat+$phy+$che;
$avg=$total/5;
$result="Fail";
$remarks="Pass";
$min=35;
$max=100;
if($gen=="Male")
$scode="Male";
$gen="S/o";
else
$scode="Female";
$gen="D/o";
$result="Fail";
else
{
if(($avg>=35) && ($avg<50))
$result="Third Class";
$result="Second Class";
if($avg>=60)
$result="First Class";
$remarks="Pass";
?>
<center>
<table border=1>
<br> <br>
<b>
<?php
echo $cname;
?>
</b>
</font>
</td>
</tr>
</table>
</td>
</tr>
<?php
echo $sname;
?>
<? php
echo $gen;
?>
<?php
?>
<tr> <td> <font size='4'> <?php echo "Date of Birth ".$dob ?>
</table>
</td>
</tr>
<tr>
<tr>
</tr>
<?php
if($hin<35)
$remarks="Fail";
else
$remarks="Pass";
?>
<tr>
<td> 101 </td> <td> Hindi </td> <td> 35 </td> <td> 100 </td> <td> <?php echo $hin; ?> <td> <?php
</tr>
<?php
if($eng<35)
$remarks="Fail";
else
$remarks="Pass";
?>
<tr>
<td> 102 </td> <td> English </td> <td> 35 </td> <td> 100 </td> <td> <?php echo $eng; ?> <td> <?
php
</tr>
<?php
if($mat<35)
$remarks="Fail";
else
$remarks="Pass";
?>
<tr>
<td> 103 </td> <td> Maths </td> <td> 35 </td> <td> 100 </td> <td> <?php echo $mat; ?> <td> <?
php
</tr>
<?php
if($phy<35)
$remarks="Fail";
else
$remarks="Pass";
?>
<tr>
<td> 104 </td> <td> Physis </td> <td> 35 </td> <td> 100 </td> <td> <?php echo $phy; ?> <td> <?php
</tr>
<?php
if($che<35)
$remarks="Fail";
else
$remarks="Pass";
?>
<tr>
<td> 101 </td> <td> Chemistry </td> <td> 35 </td> <td> 100 </td> <td> <?php echo $che; ?> <td>
</tr>
<tr>
<td> </td> <td> </td> <td> <b> Total </b> </td> <td> <b> 500 </b> </td> <td> <b> <?php echo
$total;
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr> <td> <b> <font size='4'> Result: <?php echo $result; ?> <font>
</b>
</td> </tr>
</table>
</td>
</tr>
</table>
</center>
</html>
OUTPUT