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

PHP 3-2

The document contains PHP code to perform operations on student marksheets like adding, displaying and calculating details. It includes form to enter student details and code to display the filled form in a formatted marksheet. On submission of form, the PHP code retrieves the data, calculates total, average and result and displays it in a formatted marksheet.

Uploaded by

Sanjeev Smasher
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)
12 views

PHP 3-2

The document contains PHP code to perform operations on student marksheets like adding, displaying and calculating details. It includes form to enter student details and code to display the filled form in a formatted marksheet. On submission of form, the PHP code retrieves the data, calculates total, average and result and displays it in a formatted marksheet.

Uploaded by

Sanjeev Smasher
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/ 34

TABLE CALCULATION IN PHP

<html>

<body>

<CENTER><h3><br>PROGRAM FOR ADDING ROWS AND ADDING COLUMNS</br></h3></CENTER>

<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>

<title> using form as input</title>

</head>

<body><h2><CENTER> FINDING FACTORIAL OF THE GIVEN NUMBER </h2><br>

<form method = "POST" action ="<?php echo $_SERVER['PHP_SELF'];?>"><center>

Enter the Number:

<input type = "text" name="num" size = "5"><br><br><br><center><br><br><br>

<input type = "submit" name="submit" value ="submit form"><br><br><br>

</form>

<?php

$number=$_POST["num"];

echo"<br>";

$fact = 1;

for($i=1;$i<=$number;$i++)

$fact = $fact*$i;

echo "FACTORIAL OF THE GIVEN NUMBER : ".$number."is ".$fact;

?>

</body>

</html>
OUTPUT
MULTIPLICATION IN PHP

<html>

<head>

<title> using form as input</title>

</head>

<body> <h3><CENTER> MULTIPLICATION TABLE</H3><br>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

<center>

Enter the Multiplication for:

<input type = "text" name="num" size="5"><br><br><br><center>

Enter the range of Multiplication:

<input type = "text" name="ran" size="5"><br><br><br>

<input type="submit" name="submit" value="submit form"><br> <br><br>

</form>

<?php

$number=$_POST["num"];

$range=$_POST["ran"];

echo "multiplication table generated <br><br>";

echo"<br> Multilication Table for the Number:".$number;

echo"<br> Multilication Table for the range:".$range;

echo"<br>";

for($i=1;$i<=$range; $i++)

echo $number."*".$i."=".$number*$i."<br>";

?>

</body>

</html>
OUTPUT
WORD TO DIGIT

<HTML>

<HEAD>

<TITLE>using the form as input

</title>

</head>

<body><h2><center>CONVERT A NUMBER WRITTEN IN WORDS TO DIGIT

</H2><br><form method ="POST">

<CENTER>ENTER THE NUMBER IN WORDS :

<input type ="text"name ="numw" size="15">

<br><br><br><center><br><br><br>

<input type ="submit" name="submit"

value ="submit form"><br>br<br>

</form>

<?php

$words =$_POST["numw"];

$dig=' ';

echo"<br>INPUT WORD IS :".$words;

$wdlow=strtolower($words );

$wdarray=explode(" ",$wdlow);

foreach ($wdarray as $wrds)

switch (trim($wrds))

case 'zero':$dig.='0'; break;

case'one' :$dig.='1';break ;

case 'two' :$dig.='2' ; break ;

case 'three' :$dig.= '3' ;break ;

case 'four' : $dig.='4';break ;

case 'five' :$dig.='5' ; break ;

case 'six' :$dig.='6' ; break ;


case 'seven' : $dig.= '7' ; break ;

case 'eight' : $dig.='8' ;break;

case 'nine' :$dig.='9' ; break ;

echo "<br> THE NUMBER FOR GIVEN WORDS ".$dig;

?>

</body>

</html>
OUTPUT
SUM OF FIRST N PRIME NUMBERS

<html>

<head>

<title> using form as input for n prime numbers</title>

</head>

<body><h3><CENTER>TO COMPUTE SUM OF FIRST N PRIME NUMBERS</H3><br>

<form method="POST">

<center>Enter the number of prime numbers:

<input type = "text" name="num" size="5"><br><br><br><center>

<input type = "submit" name="submit" value ="submit form"><br><br><br>

</form>

<?php

$n=$_POST["num"];

$ct = 0 ;

$i = 3;

$c = 0;

$sum =0;

if($n>1)

echo"The Prime numbers are : <br>2";

$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++;

echo"<br> the sum of first ".$n."prime number is ".$sum;

else

echo "<br>THE GIVEN NUMBER IS LESS THAN OR EQUAL TO 1";

?>

</body>

</html>
OUTPUT
Colourise first character

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<?php

function colorizeFirstCharacter($word, $color)

$characters = mb_str_split($word);

$firstCharacter = array_shift($characters);

$styledFirstCharacter = "<span style='color: $color;'>$firstCharacter</span>";

$result = $styledFirstCharacter . implode('', $characters);

return $result;

$word = "BORDER"; // Replace this with the word you want to modify

$color = "green"; // Replace this with the desired color

$result = colorizeFirstCharacter($word, $color);

echo "Original word: $word\n";

echo "Modified word: $result\n";

?>

</body>

</html>
OUTPUT
Reverse and write file

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<?php

function reverseAndWriteToFile($inputFileName, $outputFileName)

$content = file_get_contents($inputFileName);

if ($content === false) {

die("Error reading file: $inputFileName");

$reversedContent = strrev($content);

$writeResult = file_put_contents($outputFileName, $reversedContent);

if ($writeResult === false) {

die("Error writing to file: $outputFileName");

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">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>E-MAIL VALIDATION</title>

</head>

<body>

<?php

function isValidEmail($email) {

// Use filter_var with FILTER_VALIDATE_EMAIL filter

return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;

$email1 = "[email protected]";

$email2 = "invalid_email";

if (isValidEmail($email1)) {

echo "$email1 is a valid email address.\n";

} else {

echo "$email1 is not a valid email address.\n";

if (isValidEmail($email2)) {

echo "$email2 is a valid email address.\n";

} else {

echo "$email2 is not a valid email address.\n";

?>

</body>

</html>
OUTPUT
RENAME TXT TO XTX

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<?php

function renameTxtToXtx()

$files = glob("*.txt");

if ($files === false) {

die("Error listing files in the current directory.");

foreach ($files as $file) {

$newName = pathinfo($file, PATHINFO_FILENAME) . ".xtx";

if (rename($file, $newName)) {

echo "File renamed: $file to $newName\n";

} else {

echo "Error renaming file: $file\n";

renameTxtToXtx();

?>

</body>

</html>
OUTPUT
PERFORM TASK WITH DELAY

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<?php

function performTaskWithDelay($seconds)

echo "Task started\n";

sleep($seconds);

echo "Task completed after $seconds seconds\n";

$delayInSeconds = 10; // Replace this with the desired delay in seconds

performTaskWithDelay($delayInSeconds);

?>

</body>

</html>
OUTPUT
Read and print the E-mail address from xml document

<!DOCTYPE html>

<html>

<body>

<?php

$myXMLData =

"<?xml version='1.0' encoding='UTF-8'?>

<note>

<to>Tove</to>

<from>Jani</from>

<heading>E-mail address </heading>

<body>[email protected]</body>

<body>[email protected]</body>

<body>[email protected]</body>

<body>[email protected]</body>

</note>";

$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");

print_r($xml);

?>

</body>

</html>
OUTPUT
Student marksheet operations

Sd.php

<html>

<form action="res.php" method="get">

<table>

<caption> STUDENT MARKSHEET FORM </caption>

<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> Gender </td>

<td>

<input type=radio name=gen size=30 value="Male"> Male

<input type=radio name=gen size=30 value="Female"> Female

</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";

if( ($hin<35) || ($eng<35) || ($mat<35) || ($phy<35) || ($che<35) )

$result="Fail";

else

{
if(($avg>=35) && ($avg<50))

$result="Third Class";

if(($avg>=50) && ($avg<60))

$result="Second Class";

if($avg>=60)

$result="First Class";

$remarks="Pass";

?>

<center>

<table border=1>

<tr> <td> <table width=100%>

<tr> <td> <img src='mad.jpg' widht=120 height=120> </td>

<td> <b> <font size='5'> MADRAS UNIVERSITY </font>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </b>

<br> <br>

<font size='4' color='grey'>

<b>

<?php

echo $cname;

?>

</b>

</font>

</td>

</tr>

</table>

</td>

</tr>

<tr> <td> <table width=100%>

<tr> <td> <font size='4'>

<?php
echo $sname;

?>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

<? php

echo $gen;

?>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

<?php

echo $gen." Mr.". $fname;

?>

</font> </td> </tr>

<tr> <td> <font size='4'> <?php echo "Date of Birth ".$dob ?>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

<?php echo "Gender ".$scode; ?> </font> </td> </tr>

</table>

</td>

</tr>

<tr>

<td> <table border=1 width=100%>

<tr>

<th> <i> Subject Code </i> </th>

<th> <i> Subject Name </i> </th>

<th> <i> Min Marks </i> </th>

<th> <i> Max Marks </i> </th>

<th> <i> Marks Obtained </i> </th>

<th> <i> Remarks </i> </th>

</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

echo $remarks; ?> </td>

</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

echo $remarks; ?> </td>

</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

echo $remarks; ?> </td>

</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

echo $remarks; ?> </td>

</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>

<?php echo $remarks; ?> </td>

</tr>

<tr>

<td> </td> <td> </td> <td> <b> Total </b> </td> <td> <b> 500 </b> </td> <td> <b> <?php echo
$total;

?> <b> </td> <td> </td> </tr>

</table>

</td>

</tr>

<tr>

<td>

<table>

<tr> <td> <b> <font size='4'> Result: &nbsp; &nbsp; &nbsp; &nbsp; <?php echo $result; ?> <font>
</b>

</td> </tr>

</table>

</td>

</tr>
</table>

</center>

</html>
OUTPUT

Directory and file list sort by modification


<html>
<head><title> DIRECTORY MODIFICATION TIME </title><head>
<body><h2><CENTER>DIRECTORY AND LIST FILE SORTED BY LAST MODIFICATION</H2><br>
<form method = "POST">
<center>
Enter the dirtectory :
<input type = "text" name="ndir" size = "5"><br><br><br><center>
<br><br><br>
<input type = "submit" name="submit" value ="submit form"><br><br><br>
</form>
<?php
$dirname=$_POST["ndir"];
IF($dirname ==".")
{
$dirpath="*";
}
else
{
$dirpath = $dirname.'/*';
}
foreach(glob($dirpath) as $filename)
{
$filesarray[filemtime($filename)]=basename($filename);
}
echo "<br> Original files:<br>";
foreach($filesarray as $modificationtime => $file)
{
echo "modification time =".$modificationtime.",filename=".$file;
echo"<br>";
}
ksort($filesarray);
echo "<br> Sorted files:<br>";
foreach($filesarray as $modificationtime => $file)
{
echo "modification time =".$modificationtime.",filename=".$file;
echo"<br>";
}
?>
</body>
</html>

You might also like