Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

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>
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>
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>
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>
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>
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>
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>
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 = "user@example.com";

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

You might also like