SlideShare a Scribd company logo
HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN
B.C.A. Semester – VI
BCA-604 : Building Application Using PHP & ASP.NET
Teaching Scheme
(per week)

Examination Scheme

Teaching Scheme
(per semester)

INT

EXT

TOTAL

Th.
(hours)

Pr.
(hours)

Total
Hours

Credit

Th.
(marks)

Pr.
(marks)

Th.
(marks)

Pr.
(marks)

Th.
(marks)

Pr.
(marks)

--

4

40

4

--

30

--

70

--

100

University Examination Duration: 3 Hours (Per Batch)
(Practical List) : PHP (50%)
1. Write a PHP program to display “Hello World” Message on Screen.
Practical-1.php
<html>
<head>
<title>Practical-1</title>
</head>
<?php
echo "<b>Hello</b> <i>World</i>";
?>
<body>
</body>
</html>
Or
Practical-1a.php
<?php
echo "<b>Hello</b> <i>World</i>";
?>
Output:
Hello World

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 1 
2. Write a PHP program to display the today’s date and current time.
Practical-2.php
<?php
print strftime('%c');
echo "<br />";
print strftime('%d/%m/%Y');
echo "<br />";
print strftime('%A, %d %B - %Y');
echo "<br />";
echo "<b>Current Day, Date and Time is:</b> " . date("D M d, Y G:i A");
?>
Output:
01/19/14 11:31:16
19/01/2014
Sunday, 19 January - 2014
Current Day, Date and Time is: Sun Jan 19, 2014 11:31 AM

3. Write a PHP program to display the Fibonacci series.
Practical-3.php
<?php
$count = 0;
$no1 = 0;
$no2 = 1;
$tot = 0;
while($count <= 10)
{
echo $tot . "<br />";
$no1 = $no2;
$no2 = $tot;
$tot = $no1 + $no2;
$count ++;
}
?>
Or
Practical-3a.php
<?php
$number=10;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 2 
$firstno=0;
$secondno=1;
$nextno=0;
$cnt=0;
echo "Fibonacci Series<br><br>";
for($cnt=0;$cnt<=$number;$cnt++)
{
if($cnt<=1)
$nextno=$cnt;
else
{
$nextno = $firstno + $secondno;
$firstno = $secondno;
$secondno = $nextno;
}
echo $nextno . "<br>";
}
?>
or
practical-3b.php
<?php
$number=10;
$i=0;
$cnt=0;
echo "Fibonacci Series<br><br>";

for($cnt=0 ;$cnt<=$number;$cnt++)
{
echo fibonacci($i) . "<br>";
$i++;
}
function fibonacci($number)
{
if ( $number == 0 )
return 0;
else if ( $number == 1 )
return 1;
else
return ( fibonacci($number-1) + fibonacci($number-2) );
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 3 
?>
Output:
0
1
1
2
3
5
8
13
21
34
55

4. Write a PHP program to calculate sum of given number.
Practical-4.php
<?php
$val1=10;
$val2=10;
function sum($val1,$val2)
{
$total=$val1+$val2;
return $total;
}
echo "<b>Sum using Function : </b>" . sum($val1,$val2);
$sum=$val1 + $val2;
echo "<br />";
echo "<b>Sum is :</b> $sum";
?>
Output:
Sum using Function : 20
Sum is : 20

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 4 
5. Write a PHP Program that will use the concept form.
Practical-5.php
<html>
<head>
<title>Practical-5 Form Concept</title>
</head>
<body>
<form name="frmdemo" action="practical-5a.php" method="post" >
<fieldset>
<legend>Enter Your Details</legend>
<table width="250px" border="2" align="center">
<tr>
<td align="right">Name</td>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<td align="right">Contact No</td>
<td><input type="text" name="txtcno"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 5 
Practical-5a.php

<?php
if(isset($_REQUEST['submit']))
{
$name=$_REQUEST['txtname'];
$cno=$_REQUEST['txtcno'];
echo "<b>Your Name is: </b>" . $name . "<br>";
echo "<b>Contact No: </b>" . $cno;
}
else
{
echo "Go Back and Press Submit button";
}
?>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 6 
6. Write a PHP program to read the employee detail using form component.
Practical-6.php
<html>
<head>
<title>Practical-6 Employee Form</title>
</head>
<body>
<form name="empfrmdemo" action="practical-6a.php" method="post" >
<fieldset>
<legend>Grow More Computer Science</legend>
<table width="360px" border="2" align="center">
<caption><b>Enter Employee Detail...</b></caption>
<tr>
<td align="right">Employee Name</td>
<td><input type="text" name="empname" size="30px"></td>
</tr>
<tr>
<td align="right">Address</td>
<td><textarea name="empadd" cols="23"></textarea></td>
</tr>
<tr>
<td align="right">Department</td>
<td><select name="empdept">
<option value="BCA" selected>BCA</option>
<option value="PGDCA">PGDCA</option>
<option value="M.Sc.(CA&IT)">MSC(CA/IT)</option>
</select>
</td>
</tr>
<tr>
<td align="right">Designation</td>
<td><select name="empdes">
<option selected="" value="Principal">Principal</option>
<option value="Professor">Professor</option>
<option value="Asst.Professor">Asst.Professor</option>
<option value="Lecturer">Lecturer</option>
<option value="Clerk">Clerk</option>
</select>
</td>
</tr>
<tr>
<td align="right">Male/Female</td>
<td>
<input type="radio" name="gender" value="male" checked="checked">Male<br>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 7 
<input type="radio" name="gender" value="female">Female
</td>
</tr>
<tr>
<td align="right">Favourite Subjects</td>
<td>
<input type="checkbox" name="favsub[]" value="Hacking" checked="checked" />Hacking<br />
<input type="checkbox" name="favsub[]" value="Photoshop" />Photoshop<br />
<input type="checkbox" name="favsub[]" value="Forensic" checked="checked"/>Forensic<br />
<input type="checkbox" name="favsub[]" value="C Language" />C Language<br />
<input type="checkbox" name="favsub[]" value="PHP" checked="checked"/>PHP
</td>
</tr>
<tr>
<td align="right">Contact No</td>
<td><input type="text" name="empcno" size="30px"></td>
</tr>
<tr>
<td align="right">E-Mail</td>
<td><input type="text" name="empmail" size="30px"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" name="emppass" size="30px"></td>
</tr>
<tr>
<td align="right">Upload Photo</td>
<td><input type="file" name="empphoto" accept="image/*" size="30px"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="empid" value="101">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 8 
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 9 
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 10 
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 11 
7. Write a PHP program to demonstrate the use of array.
Practical-7.php
<?php
/*Indexed Array*/
// Indexed Array using Method-1
$gm=array("BCA","PGDCA","MSCIT");
echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . ".";
echo "<br>";
//Indexed Array using Method-2
$gm[0]="BCA";
$gm[1]="PGDCA";
$gm[2]="MSCIT";
echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . ".";
echo "<br>Elements in Array:";
$arrsize=count($gm);
for($cnt=0;$cnt<$arrsize;$cnt++)
{
echo "<br>";
echo "<b>" . $gm[$cnt] . "</b>";
}
echo "<br>";
/*Associative Array*/
// Associative Array using Method-1
$gm=array("d1"=>"BCA","d2"=>"PGDCA","d3"=>"MSCIT");
echo "Degree is " . $gm['d1'] ;
echo "<br>";
//Associative Array using Method-2
$gm['d1']="BCA";
$gm['d2']="PGDCA";
$gm['d3']="MSCIT";
echo "Degree is " . $gm['d2'] ;
echo "<br>";
foreach($gm as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 12 
Output:
I like BCA, PGDCA and MSCIT.
I like BCA, PGDCA and MSCIT.
Elements in Array:
BCA
PGDCA
MSCIT
Degree is BCA
Degree is PGDCA
Key=d1, Value=BCA
Key=d2, Value=PGDCA
Key=d3, Value=MSCIT

8. Write a PHP program to prepare student Mark sheet using Switch statement.
Practical-8.php
<html>
<head>
<title>Practical-8 Marksheet</title>
</head>
<body>
<form name="frmdemo" action="practical-8a.php" method="post" >
<fieldset>
<legend align="center">Enter Your Name with Marks Detail</legend>
<table width="250px" border="2" align="center">
<tr>
<td align="right">Name</td>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<td align="right">Subject-1</td>
<td><input type="text" name="txtsub1"></td>
</tr>
<tr>
<td align="right">Subject-2</td>
<td><input type="text" name="txtsub2"></td>
</tr>
<tr>
<td align="right">Subject-3</td>
<td><input type="text" name="txtsub3"></td>
</tr>
<tr>
<td align="right">Subject-4</td>
<td><input type="text" name="txtsub4"></td>
</tr>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 13 
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 14 
Practical-8a.php
<?php
if(isset($_REQUEST['submit']))
{
$name=$_REQUEST['txtname'];
$sub1=$_REQUEST['txtsub1'];
$sub2=$_REQUEST['txtsub2'];
$sub3=$_REQUEST['txtsub3'];
$sub4=$_REQUEST['txtsub4'];
echo "<b>Your Name is: </b>" . $name . "<br>";
echo "<b>Your Marks Detail: </b> <br>";
echo "Subject-1: " . $sub1 . "<br>";
echo "Subject-2: " . $sub2 . "<br>";
echo "Subject-3: " . $sub3 . "<br>";
echo "Subject-4: " . $sub4 . "<br>";
$total=$sub1+$sub2+$sub3+$sub4;
echo "Total Marks: " . $total . "<br>";
$per=$total/4;
echo "Percentage: " . $per . "%<br>";
switch($per)
{
case $per<35:
echo "Grade: F" . "<br>";
break;
case $per>=35 && $per<=50:
echo "Grade: D" . "<br>";
break;
case $per>50 && $per<=60:
echo "Grade: C" . "<br>";
break;
case $per>60 && $per<=70:
echo "Grade: B" . "<br>";
break;
case $per>70 && $per<100:
echo "Grade: A" . "<br>";
break;
default:
echo "Invalid.... or out of limit";
break;
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 15 
else
{
echo "Go Back and Press Submit button";
}
?>
Output:
Your Name is: Hitesh Patel
Your Marks Detail:
Subject-1: 40
Subject-2: 40
Subject-3: 40
Subject-4: 40
Total Marks: 160
Percentage: 40%
Grade: D

9. Write a PHP program to generate the multiplication of matrix.
Practical-9.php
<?php
$p = array();
$p[] = array(1,3,-4);
$p[] = array(1,1,-2);
$p[] = array(-1,-2,5);
$q = array();
$q[] = array(8,3,0);
$q[] = array(3,10,2);
$q[] = array(0,2,6);
echo "matrix 1<br/>";
echoMatrix(3, $p);
echo "<br/>";
echo "matrix 2<br/>";
echoMatrix(3, $q);
echo "<br/>";
$r = matrixMultiply(3, $p, $q);
echo "result of matrix multiply<br/>";
echoMatrix(3, $r);

function echoMatrix($N, $r)
{
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 16 
for($i=0; $i<$N; $i++)
{
for($j=0; $j<=$N; $j++)
{
if ($j==$N)
{
echo "<br>";
}
else
{
echo $r[$i][$j];
}
if ($j<($N-1))
{
echo ", ";
}
}
}
}
function matrixMultiply($N, $p, $q)
{
//init result
$r = array();
for($i=0; $i<$N; $i++)
{
$t = array();
for($j=0; $j<$N; $j++)
{
$t[] = 0;
}
$r[] = $t;
}
//do the matrix multiply
for($i=0; $i<$N; $i++)
{
for($j=0; $j<$N; $j++)
{
$t = 0;
for($k=0; $k<$N; $k++)
{
$t += $p[$i][$k] * $q[$k][$j];
}
$r[$i][$j] = $t;
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 17 
//return result
return $r;
}
?>
Output:

Practical-9a.php
<html>
<head>
<title>Matrix Multiplication</title>
</head>
<body>
<form name="matrix" action="practical-9b.php" method="get">
<table border="2" cellpadding="2" cellspacing="3">
<caption><b>Please Enter 3x3 Matrix</b></caption>
<tr>
<td rowspan="3">Matrix-A</td>
<td>
<input name="a11" type="text" style="width: 50px"></td>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 
Page No. 18 
<td>
<input name="a12" type="text" style="width: 50px"></td>
<td>
<input name="a13" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="a21" type="text" style="width: 50px"></td>
<td>
<input name="a22" type="text" style="width: 50px"></td>
<td>
<input name="a23" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="a31" type="text" style="width: 50px"></td>
<td>
<input name="a32" type="text" style="width: 50px"></td>
<td>
<input name="a33" type="text" style="width: 50px"></td>
</tr>
<tr>
<td rowspan="3">Matrix-B</td>
<td>
<input name="b11" type="text" style="width: 50px"></td>
<td>
<input name="b12" type="text" style="width: 50px"></td>
<td>
<input name="b13" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="b21" type="text" style="width: 50px"></td>
<td>
<input name="b22" type="text" style="width: 50px"></td>
<td>
<input name="b23" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="b31" type="text" style="width: 50px"></td>
<td>
<input name="b32" type="text" style="width: 50px"></td>
<td>
<input name="b33" type="text" style="width: 50px"></td>
</tr>
<tr>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 19 
<td align="center" colspan="4">
<input name="Submit" type="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Output

Practical-9b.php

<?php
if(isset($_REQUEST['submit']))
{
$a = array();
$a[] = array($_REQUEST['a11'],$_REQUEST['a12'],$_REQUEST['a13']);
$a[] = array($_REQUEST['a21'],$_REQUEST['a22'],$_REQUEST['a23']);
$a[] = array($_REQUEST['a31'],$_REQUEST['a32'],$_REQUEST['a33']);
$b = array();
$b[] = array($_REQUEST['b11'],$_REQUEST['b12'],$_REQUEST['b13']);
$b[] = array($_REQUEST['b21'],$_REQUEST['b22'],$_REQUEST['b23']);
$b[] = array($_REQUEST['b31'],$_REQUEST['b32'],$_REQUEST['b33']);
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 20 
echo "Matrix-A<br/>";
dispmatrix(3, $a);
echo "<br/>";
echo "Matrix-B<br/>";
dispmatrix(3, $b);
echo "<br/>";
$r = matrixMultiply(3, $a, $b);
echo "Matrix Multiplication<br/>";
dispmatrix(3, $r);
}
else
{
header('location:practical-9a.php');
}
function dispmatrix($N, $r)
{
for($i=0; $i<$N; $i++)
{
for($j=0; $j<=$N; $j++)
{
if ($j==$N)
{
echo "<br>";
}
else
{
echo $r[$i][$j];
}
if ($j<($N-1))
{
echo ", ";
}
}
}
}
function matrixMultiply($N, $a, $b)
{
//init result
$r = array();
for($i=0; $i<$N; $i++)
{
$t = array();
for($j=0; $j<$N; $j++)
{
$t[] = 0;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 21 
}
$r[] = $t;
}
//do the matrix multiply
for($i=0; $i<$N; $i++)
{
for($j=0; $j<$N; $j++)
{
$t = 0;
for($k=0; $k<$N; $k++)
{
$t += $a[$i][$k] * $b[$k][$j];
}
$r[$i][$j] = $t;
}
}
//return result
return $r;
}
?>
Output:

 

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 22 
10. Write a PHP program to send Mail from PHP Script.
Practical-10.php
<?php
error_reporting(0);
$to = "me@localhost";
$subject = "This is subject Subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc@somedomain.com rn";
$header = "Cc:afgh@somedomain.com rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
Output:
Message sent successfully...

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 23 
11. Write a PHP Program for Create, Delete, and Copying file from PHP Script.
practical-11a.php
// Enter File Name to Check Whether it is Exists or Not
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11a1.php" method="post" name="filehand">
Enter File Name to Check Whether it is Exists or Not.<br />
<input type="text" name="filename" /><br />
<input type="submit" name="checkfile" value="Check File" />
</form>
</body>
</html>
Output:

practical-11a1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not.
if(isset($_REQUEST['checkfile']))
{
if (file_exists($filename))
{
echo "The file $filename exists". "<br>";
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 24 
}
else
{
echo "The file $filename does not exists". "<br>";
}
}
?>
Output:

practical-11b.php
//Create Blank File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11b1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click Here to Create Blank File<br />
<input type="submit" name="createfile" value="Create File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 25 
Output:

practical-11b1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if it is not exists then create new blank file
if(isset($_REQUEST['createfile']))
{
if (file_exists($filename))
{
echo "The file $filename exists". "<br>";
}
else
{
$handle = fopen($filename, 'w') or die('Cannot open file: '.$filename);
//Check Whether the file is created or nor.
if (file_exists($filename))
{
echo "The $filename file Successfully Created". "<br>";
}
else
{
echo "Error While Creating $filename". "<br>";
}
}
}
?>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 26 
Output:

practical-11c.php
//Create, Open File and Save Data
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11c1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Please Enter Text to save in selected file<br />
<textarea name="filedata" cols="20" rows="5"></textarea><br />
<input type="submit" name="savefile" value="Create/Save/Append File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 27 
Output:

practical-11c1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exist it append the file. if not, then create new file and store data.
if(isset($_REQUEST['savefile']))
{
if (file_exists($filename))
{
$handle = fopen($filename, 'a') or die('Cannot open file: '.$filename);
$data = " " . $_REQUEST['filedata'];
fwrite($handle, $data . PHP_EOL);
echo "File Appended Successfully...";
}
else
{
$handle = fopen($filename, 'w') or die('Cannot open file: '.$filename);
$data = 'Welcome to Grow More Institute of Computer Application';
fwrite($handle, $data);
$data = " " . $_REQUEST['filedata'];
fwrite($handle, $data . PHP_EOL);
echo "File Successfully create a file and store Contents..";
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 
Page No. 28 
}
?>
Output:

practical-11d.php
//Open File and Read Contents
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11d1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click here to Open File<br />
<input type="submit" name="openfile" value="Open/Read File" />
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 29 
practical-11d1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exists then open the file and read the contents.
if(isset($_REQUEST['openfile']))
{
if (file_exists($filename))
{
$file = fopen($filename, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br>"; //if you want to read string contents.
//echo fgetc($file). "<br>"; //if you want to read on character at a time
}
fclose($file);
}
else
{
echo "File Does Not Exists..";
}
}
?>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 30 
practical-11e.php
//Open File and Read Contents
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11e1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click here to Open File<br />
<input type="submit" name="openfile" value="Open/Read File" />
</body>
</html>
Output:

practical-11e1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exists then open the file and read the contents.
if(isset($_REQUEST['openfile']))
{
if (file_exists($filename))
{
$filehand=fopen($filename,"r") or exit("Unable to open file!");;
$data=fread($filehand,filesize($filename));
echo "<br>" . $data;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 31 
fclose($filehand);
}
else
{
echo "File Does Not Exists..";
}
}
?>
Output:

practical-11f.php
// Copy File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11f1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Please enter new file name to copy file and press copy button<br />
<input type="text" name="newfilenm" /><br />
<input type="submit" name="copyfile" value="Copy File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 32 
Output:

practical-11f1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
$newfile=$_REQUEST['newfilenm'];
//Check file exists or not. if exists then copy the file.
if(isset($_REQUEST['copyfile']))
{
if (file_exists($filename))
{
if (file_exists($newfile))
{
echo "Destination file name is already exists...";
}
else
{
//copy file
copy($filename,$newfile);
echo "File Successfully copied...";
}
}
else
{
echo "File Does Not Exists..";
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 33 
}
?>
Output:

practical-11g.php
//Delete File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11g1.php" method="post" name="filehand">
Please enter file name to delete file.<br />
<input type="text" name="deletefilenm" /><br />
<input type="submit" name="deletefile" value="Delete File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 34 
Output:

practical-11g1.php
<?php
//Check file exists or not. if exists then copy the file.
$delfile=$_REQUEST['deletefilenm'];
if(isset($_REQUEST['deletefile']))
{
if (file_exists($delfile))
{
//delete file
unlink($delfile);
if (file_exists($delfile))
{
echo "File Not Deleted";
}
else
{
echo "File Successfully Deleted...";
}
}
else
{
echo "File Does Not Exists..";
}
}
?>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 35 
Output:

practical-11h.php
//File Information
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11h1.php" method="post" name="filehand">
Please enter file name to get File Information.<br />
<input type="text" name="filenminfo" /><br />
<input type="submit" name="fileinfo" value="Get File Information" />
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 36 
practical-11h1.php
<?php
//Check file exists or not. if exists then Display File Information.
$filename=$_REQUEST['filenminfo'];
if(isset($_REQUEST['fileinfo']))
{
if (file_exists($filename))
{
if (is_writable($filename))
{
echo "The file is writable". "<br>";
}
else
{
echo "The file is not writable". "<br>";
}
if (is_readable($filename))
{
echo "The file is readable". "<br>";
}
else
{
echo "The file is not readable". "<br>";
}
echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename)) . "<br>";
echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename)) . "<br>";
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)) . "<br>";
echo "File Size ($filename):" . filesize($filename) . " bytes" . "<br>";
$path = dirname(__FILE__);
echo "Full path: " . $path . "<br>";
$path_parts = pathinfo($filename);
echo $path_parts['dirname'], "<br>";
echo $path_parts['basename'], "<br>";
echo $path_parts['extension'], "<br>";
echo $path_parts['filename'], "<br>";
echo realpath($filename) . "<br>";
}
else
{
echo "File Does Not Exists..";
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 37 
?>
Output:

practical-11i.php
// View Files with Links
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<p>List of Files in Working Directory:</p>
<?php
$filelist = glob("*.txt");
foreach($filelist as $files)
{
echo "=> " . "<a href='$files'>$files</a>" . "<br>";
}
?>
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 38 
Output:
 

12. Write a PHP Program to Recursive Traversals of Directory.
Practical-12.php
<?php
/*
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
*/
header('Content-Type: text/plain');

$dir = dirname(__FILE__);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $item)
{
if ($item->isFile() || $item->isDir())
{
echo $item . PHP_EOL;
}
}
?>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 39 
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 40 

More Related Content

What's hot (20)

PPTX
Event In JavaScript
ShahDhruv21
 
PPT
Java Script ppt
Priya Goyal
 
PPTX
PHP Presentation
JIGAR MAKHIJA
 
PPTX
HTML Forms
Ravinder Kamboj
 
PPT
Html Ppt
vijayanit
 
PPT
Visual programming lecture
AqsaHayat3
 
PPTX
Html ppt
Ruchi Kumari
 
PPT
Asp.net.
Naveen Sihag
 
DOCX
Computer science project work
rahulchamp2345
 
PDF
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
PDF
Html frames
eShikshak
 
PPTX
Introduction to php
Taha Malampatti
 
PDF
Web Technology Lab files with practical
Nitesh Dubey
 
PPSX
Php and MySQL
Tiji Thomas
 
DOCX
Lab manual asp.net
Vivek Kumar Sinha
 
PPT
CSS Basics
WordPress Memphis
 
PPTX
Web Development
Lena Petsenchuk
 
PPT
Html
Bhumika Ratan
 
PPTX
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
Event In JavaScript
ShahDhruv21
 
Java Script ppt
Priya Goyal
 
PHP Presentation
JIGAR MAKHIJA
 
HTML Forms
Ravinder Kamboj
 
Html Ppt
vijayanit
 
Visual programming lecture
AqsaHayat3
 
Html ppt
Ruchi Kumari
 
Asp.net.
Naveen Sihag
 
Computer science project work
rahulchamp2345
 
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
Html frames
eShikshak
 
Introduction to php
Taha Malampatti
 
Web Technology Lab files with practical
Nitesh Dubey
 
Php and MySQL
Tiji Thomas
 
Lab manual asp.net
Vivek Kumar Sinha
 
CSS Basics
WordPress Memphis
 
Web Development
Lena Petsenchuk
 
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 

Viewers also liked (9)

DOC
Practical java
nirmit
 
PDF
Practical PHP 5.3
Nate Abele
 
DOC
List of programs for practical file
swatisinghal
 
PDF
Practical PHP Deployment with Jenkins
Adam Culp
 
PDF
Types of Error in PHP
Vineet Kumar Saini
 
PDF
Bca sem 5 c# practical
Hitesh Patel
 
PDF
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
PDF
Php tutorial
Niit
 
Practical java
nirmit
 
Practical PHP 5.3
Nate Abele
 
List of programs for practical file
swatisinghal
 
Practical PHP Deployment with Jenkins
Adam Culp
 
Types of Error in PHP
Vineet Kumar Saini
 
Bca sem 5 c# practical
Hitesh Patel
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
Php tutorial
Niit
 
Ad

Similar to Bca sem 6 php practicals 1to12 (20)

PDF
Practica n° 7
rafobarrientos
 
DOCX
Advance java
Vivek Kumar Sinha
 
DOCX
Print this
himanii313
 
DOC
14922 java script built (1)
dineshrana201992
 
PDF
L9. Math object in JS, CSE 202, BN11.pdf
SauravBarua11
 
PDF
Groovy kind of test
OPITZ CONSULTING Deutschland
 
PDF
Groovy kind of test
Torsten Mandry
 
PPT
Система рендеринга в Magento
Magecom Ukraine
 
DOC
Ex[1].3 php db connectivity
Mouli Chandira
 
PPTX
Javascript 1
pavishkumarsingh
 
PDF
Your Custom WordPress Admin Pages Suck
Anthony Montalbano
 
DOCX
Html file
Pawan Mishra
 
PDF
Vaadin Components @ Angular U
Joonas Lehtinen
 
PPT
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
PDF
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
PDF
Enjoy the vue.js
TechExeter
 
PDF
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 
PDF
Html Hands On
corneliuskoo
 
PDF
#3 HTML & CSS [know-how]
Dalibor Gogic
 
Practica n° 7
rafobarrientos
 
Advance java
Vivek Kumar Sinha
 
Print this
himanii313
 
14922 java script built (1)
dineshrana201992
 
L9. Math object in JS, CSE 202, BN11.pdf
SauravBarua11
 
Groovy kind of test
OPITZ CONSULTING Deutschland
 
Groovy kind of test
Torsten Mandry
 
Система рендеринга в Magento
Magecom Ukraine
 
Ex[1].3 php db connectivity
Mouli Chandira
 
Javascript 1
pavishkumarsingh
 
Your Custom WordPress Admin Pages Suck
Anthony Montalbano
 
Html file
Pawan Mishra
 
Vaadin Components @ Angular U
Joonas Lehtinen
 
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
Enjoy the vue.js
TechExeter
 
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 
Html Hands On
corneliuskoo
 
#3 HTML & CSS [know-how]
Dalibor Gogic
 
Ad

Recently uploaded (20)

PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 

Bca sem 6 php practicals 1to12

  • 1. HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN B.C.A. Semester – VI BCA-604 : Building Application Using PHP & ASP.NET Teaching Scheme (per week) Examination Scheme Teaching Scheme (per semester) INT EXT TOTAL Th. (hours) Pr. (hours) Total Hours Credit Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) -- 4 40 4 -- 30 -- 70 -- 100 University Examination Duration: 3 Hours (Per Batch) (Practical List) : PHP (50%) 1. Write a PHP program to display “Hello World” Message on Screen. Practical-1.php <html> <head> <title>Practical-1</title> </head> <?php echo "<b>Hello</b> <i>World</i>"; ?> <body> </body> </html> Or Practical-1a.php <?php echo "<b>Hello</b> <i>World</i>"; ?> Output: Hello World Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 1 
  • 2. 2. Write a PHP program to display the today’s date and current time. Practical-2.php <?php print strftime('%c'); echo "<br />"; print strftime('%d/%m/%Y'); echo "<br />"; print strftime('%A, %d %B - %Y'); echo "<br />"; echo "<b>Current Day, Date and Time is:</b> " . date("D M d, Y G:i A"); ?> Output: 01/19/14 11:31:16 19/01/2014 Sunday, 19 January - 2014 Current Day, Date and Time is: Sun Jan 19, 2014 11:31 AM 3. Write a PHP program to display the Fibonacci series. Practical-3.php <?php $count = 0; $no1 = 0; $no2 = 1; $tot = 0; while($count <= 10) { echo $tot . "<br />"; $no1 = $no2; $no2 = $tot; $tot = $no1 + $no2; $count ++; } ?> Or Practical-3a.php <?php $number=10; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 2 
  • 3. $firstno=0; $secondno=1; $nextno=0; $cnt=0; echo "Fibonacci Series<br><br>"; for($cnt=0;$cnt<=$number;$cnt++) { if($cnt<=1) $nextno=$cnt; else { $nextno = $firstno + $secondno; $firstno = $secondno; $secondno = $nextno; } echo $nextno . "<br>"; } ?> or practical-3b.php <?php $number=10; $i=0; $cnt=0; echo "Fibonacci Series<br><br>"; for($cnt=0 ;$cnt<=$number;$cnt++) { echo fibonacci($i) . "<br>"; $i++; } function fibonacci($number) { if ( $number == 0 ) return 0; else if ( $number == 1 ) return 1; else return ( fibonacci($number-1) + fibonacci($number-2) ); } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 3 
  • 4. ?> Output: 0 1 1 2 3 5 8 13 21 34 55 4. Write a PHP program to calculate sum of given number. Practical-4.php <?php $val1=10; $val2=10; function sum($val1,$val2) { $total=$val1+$val2; return $total; } echo "<b>Sum using Function : </b>" . sum($val1,$val2); $sum=$val1 + $val2; echo "<br />"; echo "<b>Sum is :</b> $sum"; ?> Output: Sum using Function : 20 Sum is : 20 Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 4 
  • 5. 5. Write a PHP Program that will use the concept form. Practical-5.php <html> <head> <title>Practical-5 Form Concept</title> </head> <body> <form name="frmdemo" action="practical-5a.php" method="post" > <fieldset> <legend>Enter Your Details</legend> <table width="250px" border="2" align="center"> <tr> <td align="right">Name</td> <td><input type="text" name="txtname"></td> </tr> <tr> <td align="right">Contact No</td> <td><input type="text" name="txtcno"></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"> </td> </tr> </table> </fieldset> </form> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 5 
  • 6. Practical-5a.php <?php if(isset($_REQUEST['submit'])) { $name=$_REQUEST['txtname']; $cno=$_REQUEST['txtcno']; echo "<b>Your Name is: </b>" . $name . "<br>"; echo "<b>Contact No: </b>" . $cno; } else { echo "Go Back and Press Submit button"; } ?> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 6 
  • 7. 6. Write a PHP program to read the employee detail using form component. Practical-6.php <html> <head> <title>Practical-6 Employee Form</title> </head> <body> <form name="empfrmdemo" action="practical-6a.php" method="post" > <fieldset> <legend>Grow More Computer Science</legend> <table width="360px" border="2" align="center"> <caption><b>Enter Employee Detail...</b></caption> <tr> <td align="right">Employee Name</td> <td><input type="text" name="empname" size="30px"></td> </tr> <tr> <td align="right">Address</td> <td><textarea name="empadd" cols="23"></textarea></td> </tr> <tr> <td align="right">Department</td> <td><select name="empdept"> <option value="BCA" selected>BCA</option> <option value="PGDCA">PGDCA</option> <option value="M.Sc.(CA&IT)">MSC(CA/IT)</option> </select> </td> </tr> <tr> <td align="right">Designation</td> <td><select name="empdes"> <option selected="" value="Principal">Principal</option> <option value="Professor">Professor</option> <option value="Asst.Professor">Asst.Professor</option> <option value="Lecturer">Lecturer</option> <option value="Clerk">Clerk</option> </select> </td> </tr> <tr> <td align="right">Male/Female</td> <td> <input type="radio" name="gender" value="male" checked="checked">Male<br> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 7 
  • 8. <input type="radio" name="gender" value="female">Female </td> </tr> <tr> <td align="right">Favourite Subjects</td> <td> <input type="checkbox" name="favsub[]" value="Hacking" checked="checked" />Hacking<br /> <input type="checkbox" name="favsub[]" value="Photoshop" />Photoshop<br /> <input type="checkbox" name="favsub[]" value="Forensic" checked="checked"/>Forensic<br /> <input type="checkbox" name="favsub[]" value="C Language" />C Language<br /> <input type="checkbox" name="favsub[]" value="PHP" checked="checked"/>PHP </td> </tr> <tr> <td align="right">Contact No</td> <td><input type="text" name="empcno" size="30px"></td> </tr> <tr> <td align="right">E-Mail</td> <td><input type="text" name="empmail" size="30px"></td> </tr> <tr> <td align="right">Password</td> <td><input type="password" name="emppass" size="30px"></td> </tr> <tr> <td align="right">Upload Photo</td> <td><input type="file" name="empphoto" accept="image/*" size="30px"></td> </tr> <tr> <td colspan="2" align="center"> <input type="hidden" name="empid" value="101"> <input type="submit" name="submit" value="Submit"> </td> </tr> </table> </fieldset> </form> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 8 
  • 12. 7. Write a PHP program to demonstrate the use of array. Practical-7.php <?php /*Indexed Array*/ // Indexed Array using Method-1 $gm=array("BCA","PGDCA","MSCIT"); echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . "."; echo "<br>"; //Indexed Array using Method-2 $gm[0]="BCA"; $gm[1]="PGDCA"; $gm[2]="MSCIT"; echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . "."; echo "<br>Elements in Array:"; $arrsize=count($gm); for($cnt=0;$cnt<$arrsize;$cnt++) { echo "<br>"; echo "<b>" . $gm[$cnt] . "</b>"; } echo "<br>"; /*Associative Array*/ // Associative Array using Method-1 $gm=array("d1"=>"BCA","d2"=>"PGDCA","d3"=>"MSCIT"); echo "Degree is " . $gm['d1'] ; echo "<br>"; //Associative Array using Method-2 $gm['d1']="BCA"; $gm['d2']="PGDCA"; $gm['d3']="MSCIT"; echo "Degree is " . $gm['d2'] ; echo "<br>"; foreach($gm as $x=>$x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 12 
  • 13. Output: I like BCA, PGDCA and MSCIT. I like BCA, PGDCA and MSCIT. Elements in Array: BCA PGDCA MSCIT Degree is BCA Degree is PGDCA Key=d1, Value=BCA Key=d2, Value=PGDCA Key=d3, Value=MSCIT 8. Write a PHP program to prepare student Mark sheet using Switch statement. Practical-8.php <html> <head> <title>Practical-8 Marksheet</title> </head> <body> <form name="frmdemo" action="practical-8a.php" method="post" > <fieldset> <legend align="center">Enter Your Name with Marks Detail</legend> <table width="250px" border="2" align="center"> <tr> <td align="right">Name</td> <td><input type="text" name="txtname"></td> </tr> <tr> <td align="right">Subject-1</td> <td><input type="text" name="txtsub1"></td> </tr> <tr> <td align="right">Subject-2</td> <td><input type="text" name="txtsub2"></td> </tr> <tr> <td align="right">Subject-3</td> <td><input type="text" name="txtsub3"></td> </tr> <tr> <td align="right">Subject-4</td> <td><input type="text" name="txtsub4"></td> </tr> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 13 
  • 14. <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"></td> </tr> </table> </fieldset> </form> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 14 
  • 15. Practical-8a.php <?php if(isset($_REQUEST['submit'])) { $name=$_REQUEST['txtname']; $sub1=$_REQUEST['txtsub1']; $sub2=$_REQUEST['txtsub2']; $sub3=$_REQUEST['txtsub3']; $sub4=$_REQUEST['txtsub4']; echo "<b>Your Name is: </b>" . $name . "<br>"; echo "<b>Your Marks Detail: </b> <br>"; echo "Subject-1: " . $sub1 . "<br>"; echo "Subject-2: " . $sub2 . "<br>"; echo "Subject-3: " . $sub3 . "<br>"; echo "Subject-4: " . $sub4 . "<br>"; $total=$sub1+$sub2+$sub3+$sub4; echo "Total Marks: " . $total . "<br>"; $per=$total/4; echo "Percentage: " . $per . "%<br>"; switch($per) { case $per<35: echo "Grade: F" . "<br>"; break; case $per>=35 && $per<=50: echo "Grade: D" . "<br>"; break; case $per>50 && $per<=60: echo "Grade: C" . "<br>"; break; case $per>60 && $per<=70: echo "Grade: B" . "<br>"; break; case $per>70 && $per<100: echo "Grade: A" . "<br>"; break; default: echo "Invalid.... or out of limit"; break; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 15 
  • 16. else { echo "Go Back and Press Submit button"; } ?> Output: Your Name is: Hitesh Patel Your Marks Detail: Subject-1: 40 Subject-2: 40 Subject-3: 40 Subject-4: 40 Total Marks: 160 Percentage: 40% Grade: D 9. Write a PHP program to generate the multiplication of matrix. Practical-9.php <?php $p = array(); $p[] = array(1,3,-4); $p[] = array(1,1,-2); $p[] = array(-1,-2,5); $q = array(); $q[] = array(8,3,0); $q[] = array(3,10,2); $q[] = array(0,2,6); echo "matrix 1<br/>"; echoMatrix(3, $p); echo "<br/>"; echo "matrix 2<br/>"; echoMatrix(3, $q); echo "<br/>"; $r = matrixMultiply(3, $p, $q); echo "result of matrix multiply<br/>"; echoMatrix(3, $r); function echoMatrix($N, $r) { Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 16 
  • 17. for($i=0; $i<$N; $i++) { for($j=0; $j<=$N; $j++) { if ($j==$N) { echo "<br>"; } else { echo $r[$i][$j]; } if ($j<($N-1)) { echo ", "; } } } } function matrixMultiply($N, $p, $q) { //init result $r = array(); for($i=0; $i<$N; $i++) { $t = array(); for($j=0; $j<$N; $j++) { $t[] = 0; } $r[] = $t; } //do the matrix multiply for($i=0; $i<$N; $i++) { for($j=0; $j<$N; $j++) { $t = 0; for($k=0; $k<$N; $k++) { $t += $p[$i][$k] * $q[$k][$j]; } $r[$i][$j] = $t; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 17 
  • 18. //return result return $r; } ?> Output: Practical-9a.php <html> <head> <title>Matrix Multiplication</title> </head> <body> <form name="matrix" action="practical-9b.php" method="get"> <table border="2" cellpadding="2" cellspacing="3"> <caption><b>Please Enter 3x3 Matrix</b></caption> <tr> <td rowspan="3">Matrix-A</td> <td> <input name="a11" type="text" style="width: 50px"></td> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 18 
  • 19. <td> <input name="a12" type="text" style="width: 50px"></td> <td> <input name="a13" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="a21" type="text" style="width: 50px"></td> <td> <input name="a22" type="text" style="width: 50px"></td> <td> <input name="a23" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="a31" type="text" style="width: 50px"></td> <td> <input name="a32" type="text" style="width: 50px"></td> <td> <input name="a33" type="text" style="width: 50px"></td> </tr> <tr> <td rowspan="3">Matrix-B</td> <td> <input name="b11" type="text" style="width: 50px"></td> <td> <input name="b12" type="text" style="width: 50px"></td> <td> <input name="b13" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="b21" type="text" style="width: 50px"></td> <td> <input name="b22" type="text" style="width: 50px"></td> <td> <input name="b23" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="b31" type="text" style="width: 50px"></td> <td> <input name="b32" type="text" style="width: 50px"></td> <td> <input name="b33" type="text" style="width: 50px"></td> </tr> <tr> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 19 
  • 20. <td align="center" colspan="4"> <input name="Submit" type="submit" value="submit"></td> </tr> </table> </form> </body> </html> Output Practical-9b.php <?php if(isset($_REQUEST['submit'])) { $a = array(); $a[] = array($_REQUEST['a11'],$_REQUEST['a12'],$_REQUEST['a13']); $a[] = array($_REQUEST['a21'],$_REQUEST['a22'],$_REQUEST['a23']); $a[] = array($_REQUEST['a31'],$_REQUEST['a32'],$_REQUEST['a33']); $b = array(); $b[] = array($_REQUEST['b11'],$_REQUEST['b12'],$_REQUEST['b13']); $b[] = array($_REQUEST['b21'],$_REQUEST['b22'],$_REQUEST['b23']); $b[] = array($_REQUEST['b31'],$_REQUEST['b32'],$_REQUEST['b33']); Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 20 
  • 21. echo "Matrix-A<br/>"; dispmatrix(3, $a); echo "<br/>"; echo "Matrix-B<br/>"; dispmatrix(3, $b); echo "<br/>"; $r = matrixMultiply(3, $a, $b); echo "Matrix Multiplication<br/>"; dispmatrix(3, $r); } else { header('location:practical-9a.php'); } function dispmatrix($N, $r) { for($i=0; $i<$N; $i++) { for($j=0; $j<=$N; $j++) { if ($j==$N) { echo "<br>"; } else { echo $r[$i][$j]; } if ($j<($N-1)) { echo ", "; } } } } function matrixMultiply($N, $a, $b) { //init result $r = array(); for($i=0; $i<$N; $i++) { $t = array(); for($j=0; $j<$N; $j++) { $t[] = 0; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 21 
  • 22. } $r[] = $t; } //do the matrix multiply for($i=0; $i<$N; $i++) { for($j=0; $j<$N; $j++) { $t = 0; for($k=0; $k<$N; $k++) { $t += $a[$i][$k] * $b[$k][$j]; } $r[$i][$j] = $t; } } //return result return $r; } ?> Output:   Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 22 
  • 23. 10. Write a PHP program to send Mail from PHP Script. Practical-10.php <?php error_reporting(0); $to = "me@localhost"; $subject = "This is subject Subject"; $message = "<b>This is HTML message.</b>"; $message .= "<h1>This is headline.</h1>"; $header = "From:[email protected] rn"; $header = "Cc:[email protected] rn"; $header .= "MIME-Version: 1.0rn"; $header .= "Content-type: text/htmlrn"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; } ?> Output: Message sent successfully... Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 23 
  • 24. 11. Write a PHP Program for Create, Delete, and Copying file from PHP Script. practical-11a.php // Enter File Name to Check Whether it is Exists or Not <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11a1.php" method="post" name="filehand"> Enter File Name to Check Whether it is Exists or Not.<br /> <input type="text" name="filename" /><br /> <input type="submit" name="checkfile" value="Check File" /> </form> </body> </html> Output: practical-11a1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if(isset($_REQUEST['checkfile'])) { if (file_exists($filename)) { echo "The file $filename exists". "<br>"; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 24 
  • 25. } else { echo "The file $filename does not exists". "<br>"; } } ?> Output: practical-11b.php //Create Blank File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11b1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click Here to Create Blank File<br /> <input type="submit" name="createfile" value="Create File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 25 
  • 26. Output: practical-11b1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if it is not exists then create new blank file if(isset($_REQUEST['createfile'])) { if (file_exists($filename)) { echo "The file $filename exists". "<br>"; } else { $handle = fopen($filename, 'w') or die('Cannot open file: '.$filename); //Check Whether the file is created or nor. if (file_exists($filename)) { echo "The $filename file Successfully Created". "<br>"; } else { echo "Error While Creating $filename". "<br>"; } } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 26 
  • 27. Output: practical-11c.php //Create, Open File and Save Data <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11c1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Please Enter Text to save in selected file<br /> <textarea name="filedata" cols="20" rows="5"></textarea><br /> <input type="submit" name="savefile" value="Create/Save/Append File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 27 
  • 28. Output: practical-11c1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exist it append the file. if not, then create new file and store data. if(isset($_REQUEST['savefile'])) { if (file_exists($filename)) { $handle = fopen($filename, 'a') or die('Cannot open file: '.$filename); $data = " " . $_REQUEST['filedata']; fwrite($handle, $data . PHP_EOL); echo "File Appended Successfully..."; } else { $handle = fopen($filename, 'w') or die('Cannot open file: '.$filename); $data = 'Welcome to Grow More Institute of Computer Application'; fwrite($handle, $data); $data = " " . $_REQUEST['filedata']; fwrite($handle, $data . PHP_EOL); echo "File Successfully create a file and store Contents.."; } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 28 
  • 29. } ?> Output: practical-11d.php //Open File and Read Contents <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11d1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click here to Open File<br /> <input type="submit" name="openfile" value="Open/Read File" /> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 29 
  • 30. practical-11d1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exists then open the file and read the contents. if(isset($_REQUEST['openfile'])) { if (file_exists($filename)) { $file = fopen($filename, "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)) { echo fgets($file). "<br>"; //if you want to read string contents. //echo fgetc($file). "<br>"; //if you want to read on character at a time } fclose($file); } else { echo "File Does Not Exists.."; } } ?> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 30 
  • 31. practical-11e.php //Open File and Read Contents <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11e1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click here to Open File<br /> <input type="submit" name="openfile" value="Open/Read File" /> </body> </html> Output: practical-11e1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exists then open the file and read the contents. if(isset($_REQUEST['openfile'])) { if (file_exists($filename)) { $filehand=fopen($filename,"r") or exit("Unable to open file!");; $data=fread($filehand,filesize($filename)); echo "<br>" . $data; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 31 
  • 32. fclose($filehand); } else { echo "File Does Not Exists.."; } } ?> Output: practical-11f.php // Copy File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11f1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Please enter new file name to copy file and press copy button<br /> <input type="text" name="newfilenm" /><br /> <input type="submit" name="copyfile" value="Copy File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 32 
  • 33. Output: practical-11f1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; $newfile=$_REQUEST['newfilenm']; //Check file exists or not. if exists then copy the file. if(isset($_REQUEST['copyfile'])) { if (file_exists($filename)) { if (file_exists($newfile)) { echo "Destination file name is already exists..."; } else { //copy file copy($filename,$newfile); echo "File Successfully copied..."; } } else { echo "File Does Not Exists.."; } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 33 
  • 34. } ?> Output: practical-11g.php //Delete File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11g1.php" method="post" name="filehand"> Please enter file name to delete file.<br /> <input type="text" name="deletefilenm" /><br /> <input type="submit" name="deletefile" value="Delete File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 34 
  • 35. Output: practical-11g1.php <?php //Check file exists or not. if exists then copy the file. $delfile=$_REQUEST['deletefilenm']; if(isset($_REQUEST['deletefile'])) { if (file_exists($delfile)) { //delete file unlink($delfile); if (file_exists($delfile)) { echo "File Not Deleted"; } else { echo "File Successfully Deleted..."; } } else { echo "File Does Not Exists.."; } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 35 
  • 36. Output: practical-11h.php //File Information <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11h1.php" method="post" name="filehand"> Please enter file name to get File Information.<br /> <input type="text" name="filenminfo" /><br /> <input type="submit" name="fileinfo" value="Get File Information" /> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 36 
  • 37. practical-11h1.php <?php //Check file exists or not. if exists then Display File Information. $filename=$_REQUEST['filenminfo']; if(isset($_REQUEST['fileinfo'])) { if (file_exists($filename)) { if (is_writable($filename)) { echo "The file is writable". "<br>"; } else { echo "The file is not writable". "<br>"; } if (is_readable($filename)) { echo "The file is readable". "<br>"; } else { echo "The file is not readable". "<br>"; } echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename)) . "<br>"; echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename)) . "<br>"; echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)) . "<br>"; echo "File Size ($filename):" . filesize($filename) . " bytes" . "<br>"; $path = dirname(__FILE__); echo "Full path: " . $path . "<br>"; $path_parts = pathinfo($filename); echo $path_parts['dirname'], "<br>"; echo $path_parts['basename'], "<br>"; echo $path_parts['extension'], "<br>"; echo $path_parts['filename'], "<br>"; echo realpath($filename) . "<br>"; } else { echo "File Does Not Exists.."; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 37 
  • 38. ?> Output: practical-11i.php // View Files with Links <htm> <head> <title>File Handling</title> </head> <body> <p>List of Files in Working Directory:</p> <?php $filelist = glob("*.txt"); foreach($filelist as $files) { echo "=> " . "<a href='$files'>$files</a>" . "<br>"; } ?> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 38 
  • 39. Output:   12. Write a PHP Program to Recursive Traversals of Directory. Practical-12.php <?php /* error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); */ header('Content-Type: text/plain'); $dir = dirname(__FILE__); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $item) { if ($item->isFile() || $item->isDir()) { echo $item . PHP_EOL; } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 39