Professional Documents
Culture Documents
PHP 3-1
PHP 3-1
<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>
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>
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>
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>
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>
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>
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>
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>
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>
PERFORM TASK WITH DELAY
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
function performTaskWithDelay($seconds)
sleep($seconds);
performTaskWithDelay($delayInSeconds);
?>
</body>
</html>