PHP Print Out
PHP Print Out
arrays.html
<html>
<head>
<title>Array Functions</title>
</head>
<body>
<form action="arrays.php">
</textarea><br>
</textarea> <br>
</form>
</body>
</html>
arrays.php
<?php
$a1=explode(",",$_GET['txt1']);
array($a1);
print_r($a1);
$a2=explode(",",$_GET['txt2']);
array($a2);
print_r($a2);
$a3=array_combine($a1,$a2);
print_r($a3);
$a3=array_diff($a1,$a2);
print_r($a3);
$s=$_GET['txtsearch'];
if(in_array($a3,$a1)
{
echo "Array element(".$s.")is found at the index of".array_search($s,$a1);
}
else
{
echo "Array element".$s."is not found at the index of".array_search($s,$a1);
echo "Arraysorting<br>";
sort($a1);
print_r($a1);
rsort($a1);
print_r($a1);
?>
OUTPUT
PHP PROGRAM TO DEMONSTRATE ALL CONTROL STATEMENTS (FIND
FACTORIAL OF THE GIVEN NUMBER USING IF, WHILE, DO-WHILE.)
controlfact.html
<html>
<head>
<title>Factorial calculation</title>
</head>
<body>
<form action="controlfact.php">
<center><h1>Factorial</h1></center>
</form>
</body>
</html>
controlfact.php
<?php
$n=$_GET['txtno'];
$c=$_GET['loop'];
switch($c)
{
case 1:
echo "<h1> Factorial calculation using While loop </h1>";
$f=1;
$i=1;
while($i<=$n)
{
$f=$f*$i;
$i++;
}
echo "factorial of".$n."is:".$f;
break;
case 2:
echo "<h1>Factorial calculation using Do..While loop</h1>";
$f=1;
$i=1;
do
{
$f=$f *$i;
$i++;
}while($i<=$n);
echo "factorial of".$n."is:".$f;
break;
case 3:
echo "<h1>Factorial Calculation using For Loop</h1>";
$f=1;
for($i=1;$i<=$n;$i++)
{
$f=$f*$i;
}
echo "factorial of".$n."is:".$f;
break;
}
?>
OUTPUT
INVENTORY TABLE USING KEY AND VALUE PAIRS
<html >
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
$Inventory = array (array('Wrist Watch',01,350), array('Cooler',12,1000),
array('Clutch',20,450) );
?>
<h2>Inventory Table</h2>
<table border="2" bordercolor="#000000">
<th>Sl.No</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Product Per Price</th>
<?php
foreach ($Inventory as $key => $value)
{
echo "<tr>";
echo "<td>" . ++$key . "</td> <td>" . $value[0] . "</td>";
echo "<td>" . $value[1] . "</td>";
echo "<td>" . $value[2] . "</td>";
echo "</tr> ";
}
?>
</table>
</body>
</html>
STUDENT TABLE USING KEY AND VALUE PAIRS TO SEARCH PARTICULAR
STUDENT
<html>
<head>
<title>Student Search</title>
</head>
<body>
<?php
$Students = array
(array('XXX',01,'Present'),
array('YYY',02,'Present'),
array('ZZZ',03,'Absent') );
?>
";
}
?>
</table>
<br />
<br />
funadd.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
Fun
]
add.php
<?php
function add()
$n1=$_GET['fno'];
$n2=$_GET['sno'];
$n3=$n1 + $n2;
add();
?>
OUTPUT
USER DEFINED FUNCTIONS
funsub.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
funsub.php
<?php
function sub()
$n1=$_GET['fno'];
$n2=$_GET['sno'];
$n3=$n1 - $n2;
$r=$n1."-".$n2."=".$n3;
return $r;
echo sub();
?>
OUTPUT
USER DEFINED FUNCTIONS
funmul.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
funmul.php
<?php
$n1=$_GET['txt1'];
$n2=$_GET['txt2'];
function mul($a,$b)
$c=$a*$b;
echo $a."*".$b."=".$c;
mul($n1,$n2);
?>
OUTPUT
USER DEFINED FUNCTIONS
fundiv.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
fundiv.php
<?php
$n1=$_GET['txt1'];
$n2=$_GET['txt2'];
function div($a,$b)
$c=$a/$b;
$r=$a."/".$b."=".$c;
return $r;
$ret=div($n1,$n2);
echo $ret;
?>
OUTPUT
USER DEFINED FUNCTIONS
fundef.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
fundef.php
<?php
$t=$_GET['txt1'];
$s=$_GET['txt2'];
$e=$_GET['txt3'];
function display($t,$s=1,$e=10)
for($i=$s;$i<=$e;$i++)
$a=$i*$t;
display($t,$s,$e);
display($t,$s);
display($t,$s,$e);
else
display($t);
?>
OUTPUT
PHP program to find factorial of the given number using recursion
fact.html
<html>
<head>
<title>Factorial</title>
</head>
<body>
<form action="fact.php">
</form>
</body>
</html>
fact.php
<?php
$a=$_GET['txt1'];
function fact($n)
if($n<=1)
return 1;
else
return $n*fact($n-1);
?>
OUTPUT
PHP Program to calculate nCr using include command to include the factorial function
ncr.html
<html>
<head>
<title>nCr Calculation</title>
</head>
<body>
<center><h1>nCr Calculation</h1></center>
<form action="ncr.php">
</form>
</body>
</html>
ncr.php
<?php
$n=$_GET['txt1'];
$r=$_GET['txt2'];
function factorial($number)
{
if($number<0)
{
return -1;
for($i=1;$i<=$number;$i++)
{
$result=$result*i;
}
}
function ncr($n,$r)
{
return factorial($n)/(factorial($r)*factorial($n-$r));
}
?>
PHP PROGRAM TO WORKING WITH COOKIE
CREATING COOKIE
cookie.html
<html>
<head>
<title>Creating Cookie</title>
</head>
<body>
<center><h3>CREATING COOKIE</h3></center>
<form action="cookie.php">
</form>
</body>
</html>
cookie.php
<?php
$name=$_GET['txt1'];
$password=$_GET['txt2'];
setcookie("name",$name);
setcookie("pword",$password);
?>
OUTPUT
PHP PROGRAM TO WORKING WITH COOKIE
RETRIVING COOKIES
retrieve.php
<html>
<head>
<title>Retrive Cookie</title>
</head>
<body>
<?php
if(isset($_COOKIE["name"])&&isset($_COOKIE["pword"]))
echo "<br>";
else
?>
</body>
</html>
OUTPUT
TO PROCESS PERSONAL DETAILS USING FILE
file.html
<html>
<head>
<title>File</title>
</head>
<body>
<form action="file.php">
</textarea><br>
</form>
</body>
</html>
file.php
<?php
$fname=$_GET['txt1'];
$contents=$_GET['txt2'];
$fp=fopen("$fname","w");
fwrite($fp,$contents);
fclose($fp);
?>
OUTPUT
TO PROCESS PERSONAL DETAILS USING FILE
read.html
<html>
<head>
</head>
<body>
</form>
</body>
</html>
read.php
<?php
$fname=$_POST['txtfname'];
$fp=fopen($fname,"r");
while(!(feof($fp)))
echo fgets($fp)."<br>";
fclose($fp);
?>
OUTPUT
TO DESIGN AN STUDENT MARK USING HTML FORM
AND PROCESS USING PHP
mark.html
<html>
<head>
<title>Student Marklist</title>
</head>
<body>
<form action="mark.php">
</form>
</body>
</html>
mark.php
<?php
$n=$_GET['txtname'];
$ro=$_GET['txtno'];
$j=$_GET['java'];
$m=$_GET['mat'];
$e=$_GET['eng'];
$t=$j+$m+$e;
$avg=$t/3;
if($j>=35&&$m>=35&&$e>=35)
$r="pass";
else
$r="fail";
echo "Studentname:".$n."<br>";
echo "Rollno:".$ro."<br>";
echo "Average:".$avg."<br>";
echo "result:".$r."<br>";
?>
OUTPUT
PHP PROGRAM TO DISPLAY STUDENT DETAILS USING DATABASE
insert.html
<html>
<head>
<title>Database Connection</title>
</head>
<body>
<center><h1>Database Connection</h1></center>
<pre>
</pre>
</form>
</body>
</html>
insert.php
<?php
$sname=$_POST['sname'];
$dept=$_POST['dept'];
$marks=$_POST['mark'];
$con=mysqli_connect("localhost","root","","college");
if(!$con)
{
die("Error : ". sqli_connect_error());
}
else
{
$sql="insert into secondcsc values('$sname','$dept','$marks')";
$result=mysqli_query($con,$sql);
if($result)
{
echo "Record Inserted";
}
else
{
echo "Record not Inserted";
}
}
?>
OUTPUT
display.php
<?php
$con=mysqli_connect("localhost","root","","college");
$result=mysqli_query($con,$sql);
$n=mysqli_num_rows($result);
if($n>0)
{
echo"<table>";
echo "<tr>";
echo "<th>Department</th>";
echo "<th>Marks</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row['sname'];
echo "<td>".$row['dept'];
echo "<td>".$row['mark'];
echo "</tr>";
echo "</table>";
else
?>
OUTPUT