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

PHP Lab Final1

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)
32 views

PHP Lab Final1

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

INDEX

S. No NAME OF THE PROGRAM PAGE NO


1 CONTROLS AND FUNCTIONS
2 STRING AND ARRAYS
3 GENERATE AND DISPLAY GRADE

4 STUDENT REGISTRATION FORM

5 MATH FUNCTION

6 COOKIES
7 DISPLAY STUDENT INFORMATION USING
MYSQL TABLE
8 GENBAK USING BIOPERL
9 COMPARE SEQUENCES AND FIND MUTATION
USING BIOPERL
10 SIMULATE DNA MUTATION
11 PROTEIN SEQUENCE GENERATION
12 DNA FRAGMENTS TRANSCRIPTION : DNA TO
RNA

Department of Computer Science Page 1


Ex: No- 1 CONTROL AND FUNCTIONS

AIM : Develop a PHP program using controls and functions

ALGORITHM :

STEP 1: Start the process

STEP 2: Go to the editor for coding the controls and functions programs in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create the variables and assign values to the them

STEP 5: using control statements find the biggest among two variables

STEP 6: create another block of statements for favourite site using switch
statement

STEP 7: print values and run the local host using browser

STEP 8: Execute the program.


STEP 9: Display the result.
STEP 10: Stop the process

Department of Computer Science Page 2


PROGRAM :
<?php

$first_number=7;

$second_number=21;

if($first_number>$second_number){

echo"$first_number is greater than $second_number";

else

echo"$second_number is greater than $first_number";

$favorite_site='code';

switch($favorite_site){

case'business':

echo"myfavorite site is business.tutsplus.com";

break;

case'code':

echo"myfavorite site is code.tutsplus.com";

break;

case'web design':

echo"myfavorite site is web design.tutsplus.com";

break;

case'music':

echo"myfavorite site is music.tutsplus.com";

break;

case'photography':

Department of Computer Science Page 3


echo"myfavorite site is photography.tutsplus.com";

break;

default:

echo"i like everything in tutsplus.com!";

$max=0;

echo $i=0;

echo",";

echo $j=1;

echo",";

$result=0;

while($max<10)

$result=$i+$j;

$i=$j;

$j=$result;

$max=$max+1;

echo $result;

echo",";

?>

Department of Computer Science Page 4


OUTPUT :

RESULT : The program is executed and verified successfully

Department of Computer Science Page 5


Ex: No- 2 STRING AND ARRAYS

AIM: To Develop a PHP program to implement the concept of String and arrays

ALGORITHM:

STEP 1: Start the process

STEP 2: Go to the editor for creating the associative array and strings program
in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: input associative array with necessary values

STEP 5: print the associative array using echo statement

STEP 6: save the PHP program in the server

STEP 7: Run the local host using browser and call the program

STEP 8: stop the process

Department of Computer Science Page 6


PROGRAM:

<html>

<head>

<title>associative array</title>

</head>

<body>

<?php

$marks=array(

"mohammad"=>array(

"physics"=>35,

"maths"=>30,

"chemistry"=>39

),

"qadir"=>array(

"physics"=>30,

"maths"=>32,

"chemistry"=>29

),

"zara"=>array(

"physics"=>31,

"maths"=>22,

"chemistry"=>39

);

echo"marks for mohammad in physics:";

Department of Computer Science Page 7


echo $marks['mohammad']['physics']."<br/>";

echo"marks for mohammad in maths:";

echo $marks['mohammad']['maths']."<br/>";

echo"marks for mohammad in chemistry:";

echo $marks['mohammad']['chemistry']."<br/>";

echo"the total marks of mohammad:";

echo $marks['mohammad']['physics']+$marks['mohammad']['maths']+
$marks['mohammad']

['chemistry']."<br/>";

echo"<br/>";

echo"marks for qaduir in physics:";

echo $marks['qadir']['physics']."<br/>";

echo"marks for qadir in maths:";

echo $marks['qadir']['maths']."<br/>";

echo"marks for qadir in chemistry:";

echo $marks['qadir']['chemistry']."<br/>";

echo"the total marks of qadir:";

echo $marks['qadir']['physics']+$marks['qadir']['maths']+$marks['qadir']
['chemistry']."<br/>";

echo"<br/>";

echo"marks for zara in physics:";

echo $marks['zara']['physics']."<br/>";

echo"marks for zara in maths:";

echo $marks['zara']['maths']."<br/>";

Department of Computer Science Page 8


echo"marks for zara in chemistry:";

echo $marks['zara']['chemistry']."<br/>";

echo"the total marks of zara:";

echo $marks['zara']['physics']+$marks['zara']['maths']+$marks['zara']
['chemistry']."<br/>";

echo"<br/>";

?>

</body>

</html>

Department of Computer Science Page 9


OUTPUT:

RESULT: The program is executed and verified successfully

Department of Computer Science Page 10


Ex: No- 3 GENERATE AND DISPLAY A GRADE

AIM: Develop a PHP program to generate and display a grade.

ALGORITHM:

STEP 1: Start the process

STEP 2: Go to the editor for coding the grade displaying programs in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create a form using html tags and create a table with fields student
name Marks for physics, chemistry and maths

STEP 5: check the input element is set or not using set() function

STEP 6: Add necessary fields and access value from each text field

STEP 7: Find the total marks and set the appropriate grade format using if
statement

STEP 8: Print the values using echo statement

STEP 9: save the app PHP coded program in server

STEP 10: print values and run the local host using browser

STEP 11: stop the process

Department of Computer Science Page 11


PROGRAM :

<html>

<body>

<form action="" method="post">

<center>

<table border=0>

<tr>

<td>

Student Name

</td>

<td>

<input type=text name="t1">

</td>

</tr>

<tr>

<td>

Marks for Physics

</td>

<td>

<input type=text name="t2">

</td>

</tr>

<tr>

<td>

Marks for Chemistry

Department of Computer Science Page 12


</td>

<td>

<input type=text name="t3">

</td>

</tr>

<tr>

<td>

Marks for Math

</td>

<td>

<input type=text name="t4">

</td>

</tr>

</table>

<br>

<br>

<input type=submit name="s" value="Result">

</center>

<?php

if(isset($_POST['s']))////checking whether the input element is set or not

$a=$_POST['t1'];//accessing value from 1st text box

$a1=$_POST['t2'];//accessing value from 2nd text field

$a2=$_POST['t3'];//accessing value from 3rd text field

$a3=$_POST['t4'];//accessing value from 4th text field

$sum=$a1+$a2+$a3;

Department of Computer Science Page 13


$avg=$sum/3;

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

$grade="Fail";

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

$grade="C";

if($avg>=70&&$avg<=80)

$grade="B";

if($avg>=80&&$avg<=90)

$grade="A";

if($avg>90)

$grade="E";

echo "<br>";

echo "<font size=4><center>Student is:-".$a."</center><br>";

echo "<font size=4><center>Total marks:-

".$sum."</center><br>";

echo "<font size=4><center>Grade is:-".$grade."</center>";

?>

</form>

</body>

</html>

Department of Computer Science Page 14


OUTPUT :

RESULT: The program is executed and verified successfully

Department of Computer Science Page 15


Ex: No- 4 STUDENT REGISTRATION FORM

AIM: Develop a PHP program to display student registration form

ALGORITHM:
STEP 1: Start the process

STEP 2: Go to the editor for coding the student registration details

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create a student registration form using form method

STEP 5: use field set tag for inserting fields to form

STEP 6: use legend tag function to insert student details

STEP 7: use the input type function to submit the entered the details

STEP 8: save the app PHP coded program in server

STEP 9: Run the local host using the browser and calls the program

Department of Computer Science Page 16


PROGRAM :

<html>

<head>

<title>Student Registration | PHP</title>

</head>

<body>

<div>

<?php

if(isset($_POST['create']))

echo 'Student details submitted.';

?>

</div>

<div>

<form action="registration.php" method="post">

<div class="container">

<h1>Registration</h1>

<p>Fill up the form with correct values.</p>

<label for="regno"><b>Reg no</b></label>

<input type="text" name="regno" required>

<label for="name"><b>Student Name</b></label>

<input type="text" name="name" required>

<label for="addr"><b>Address</b></label>

Department of Computer Science Page 17


<input type="text" name="addr" required>

<label for="email"><b>E-Mail</b></label>

<input type="text" name="email" required>

<label for="phonenumber"><b>Phone number</b></label>

<input type="text" name="phonenumber" required>

<input type="submit" name="create" value="Submit">

</div>

</form>

</body>

</html>

Department of Computer Science Page 18


OUTPUT:

RESULT : The program is executed and verified successfully .

Department of Computer Science Page 19


Ex: No- 5 MATH FUNCTIONS

AIM: Develop a PHP program to demonstrate Math functions.

ALGORITHM:
STEP 1: Start the process

STEP 2: Go to the editor for math function coding in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create a math form using form method

STEP 5: Use field set tag for inserting fields to form

STEP 6: Use legend tag function to insert student details

STEP 7: Use the input type function to submit entered details

STEP 8: Save the app PHP coded program in server

STEP 9: Run the local host using the browser and calls the program

Department of Computer Science Page 20


PROGRAM:

<?php

$marks1=array(360,310,310,330,313,375,456,111,256);

$marks2=array(350,340,356,330,321);

$marks3=array(630,340,570,635,434,255,298);

$max_marks = max(max($marks1),max($marks2),max($marks3));

$min_marks = min(min($marks1),min($marks2),min($marks3));

echo"Maximummarks : ",$max_marks."\n";

echo"Minimummarks : ",$min_marks."\n";

echo round( 1.65,1, PHP_ROUND_HALF_UP)."\n";

echo round( 1.65,1, PHP_ROUND_HALF_DOWN)."\n";

echo round( -1.54,1, PHP_ROUND_HALF_EVEN)."\n";

$val='4.5e3';

$ival=(int) $val;

$fval=(float) $val;

echo $ival,"\n";

echo $fval,"\n";

$odate="2012-09-12";

$newDate=date("d-m-y",strtotime($odate));

echo $newDate,"\n";

?>

Department of Computer Science Page 21


OUTPUT:

RESULT: The program is executed and verified successfully .

Department of Computer Science Page 22


Ex. No – 6 COOKIES

Aim: To develop PHP Program Using Cookies

Algorithm:
STEP 1: Start the process

STEP 2: Go to the editor for coding the cookie program in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create 3 different documents to set and get the cookie

STEP 5: use input type function to perform operations like read and delete
cookies

STEP 6: Print the values using echo statement

STEP 7: save the app PHP coded program in server

STEP 8: Run the local host using the browser and calls the program

Department of Computer Science Page 23


PROGRAM:
Phpsetcookie.php

<html>

<head>

<title>cookies</title>

<?php

setcookie("messages","No Worries for 30 days(cookie is set)",time()+3600);

?>

</head>

<body>

<h1>

seting a cookie

</h1>

The Cookie was set.

<form action="phpgetcookie.php">

<input type="submit" value="read cookies">

</form></body></html>

Phpgetcookie.php

<html>

<head><title>cookies</title>

</head>

<body>

<h1>

Reading a cookie </h1>

The cookie says:

Department of Computer Science Page 24


<?php

if(isset($_COOKIE['message']))

echo $_COOKIE['MESSAGE'];

?>

<form action="setcookie.php">

<input type="submit" value="delete cookies">

</form>

</body>

</html>

Setcookie.php

<html>

<head>

<title>cookies</title>

<?php

setcookie("message"," ",time()-3600);

?>

</head>

<body>

<h1> cookie was deleted.</h1>

<form action="phpgetcookie.php">

<input type="submit" value="back">

</form>

</body></html>

Department of Computer Science Page 25


OUTPUT:

Department of Computer Science Page 26


RESULT: The program is executed and verified successfully

Department of Computer Science Page 27


Ex: No- 7 STUDENT INFORMATION USING MYSQL TABLE

AIM: Develop a PHP program to display student information using MYSQL


table

ALGORITHM:
STEP 1: Start the process

STEP 2: Go to the editor for coding the student information program in PHP

STEP 3: Program code starts with opening and closing tag for PHP
programming

STEP 4: create a student registration form using form method

STEP 5: use field set tag for inserting fields to form

STEP 6: use legend tag function to insert student details

STEP 7: use the input type function to submit the entered the details

STEP 8: save the app PHP coded program in server

STEP 9: Run the local host using the browser and calls the program

Department of Computer Science Page 28


PROGRAM :

Student.php

<html>

<head>

<title>database</title>

</head>

<body>

<form action="student.php"method="POST">

ID:<input type="text" name="c"><br><br>

Name:<input type="text" name="a"><br><br>

City:<input type="text" name="b"><br><br>

<input type="submit"name="insert"value="INSERT">

<input type="submit"name="update"value="UPDATE">

<input type="submit"name="delete"value="DELETE">

</form>

</body>

</html>

Student.php

<html>

<head>

<title>database</title>

</head>

<body>

<?php

Department of Computer Science Page 29


if(isset($_POST['insert']))

$X=$_POST['c'];

$y=$_POST['a'];

$z=$_POST['b'];

$con=mysql_connect("localhost","root","");

mysql_select_db("prabu",$con);

mysql_query("insert into mini values('$x','$y','$z')");

echo"Row inserted";

if(isset($_POST['update']))

$X=$_POST['c'];

$y=$_POST['a'];

$z=$_POST['b'];

$con=mysql_connect("localhost","root","");

mysql_select_db("prabu",$con);

mysql_query("update mini set name='$y',place='$z'where id='$x'");

echo"Row updated";

if(isset($_POST['delete']))

$x=$_POST['e'];

$con=mysql_connect("localhost","root","");

mysql_select_db("prabu",$con);

mysql_query("delete from mini where id='$x'");

Department of Computer Science Page 30


echo"Row deleted";

?>

</body>

<html>

Department of Computer Science Page 31


OUTPUT:

RESULT: The program is executed and verified successfully

Department of Computer Science Page 32


Ex: No- 8 IMPORTING DATA FROM GENBANK USING BIOPERL

AIM: To write a script to import data from genbank using bioperl.

ALGORITHM:

STEP 1: Start the process.

STEP 2: Using Bio:: DB::Genbank import sequence from Genbank.

STEP 3: Get the sequence of (AF303112) in seq1 and trunk it in seq2 Using trunc(1, 200)

STEP 4: Print the seq2

STEP 6: Stop the process.

Department of Computer Science Page 33


CODING

:#!/local/bin/perl -w

use Bio::DB::GenBank;

$gb = new Bio::DB::GenBank();

$seq1 = $gb->get_Seq_by_acc('AF303112');

$seq2=$seq1->trunc(1, 200);

print $seq2->seq(), "\n";

exit;

Department of Computer Science Page 34


OUTPUT:

GENBANK/AF303112

GENBANK/AY050559

Department of Computer Science Page 35


RESULT: The program is executed and verified successfully

Department of Computer Science Page 36


Ex: No- 9 COMPARE SEQUENCE AND FIND MUTATION USING BIOPERL

AIM: To write a script to use sequence feature to compare sequence and find mutation using bioperl.

ALGORITHM:

STEP 1: Start the process.

STEP 2: Using file::path print the filename and open.

STEP 3: Declare sub mutate to get the current base and new base of DNA.

STEP 4:’ Do’ function is used to get the new base.

STEP 5: Print the file name to getting the sequence which is compared and mutant.

STEP 6: Stop the process

Department of Computer Science Page 37


Coding :

use File::Path;

print "\n\t MUTATION OF DNA\n\n";

print "ENTER THE FILENAME OF THE DNA SEQUENCE: ";

$dnafilename = <STDIN>;

chomp $dnafilename;

unless (open(DNAFILE, $dnafilename) )

print "Cannot open file \"$dnafilename\"\n\n";

goto h;

my $DNA = <DNAFILE>;

close DNAFILE;

my $i;

my $mutant;

$mutant = mutate($DNA);

print "Mutate DNA\n\n";

print "THE ORIGINAL DNA SEQUENCE:\n";

print "$DNA\n\n";

print "THE MUTANT DNA SEQUENCE:\n";

print "$mutant\n\n";

print "THE 15 SUCCESSIVE MUTATIONS ARE:\n\n";

for ($i=0 ; $i < 15 ; ++$i)

$mutant = mutate($mutant);

print "$mutant\n";

print WRITE "$mutant\n";

Department of Computer Science Page 38


}

sub mutate

my($dna) = @_;

my($position) = randomposition($dna);

my $current_base = substr($dna, $position, 1);

my $newbase;

do

$newbase = randomnucleotide();

until ($newbase ne $current_base);

substr($dna,$position,1,$newbase);

return $dna;

subrandomposition

my($string) = @_;

returnint rand length $string;

subrandomelement

my(@array) = @_;

return $array[rand @array];

subrandomnucleotide

my(@nucleotides) = ('A', 'C', 'G', 'T');

Department of Computer Science Page 39


returnrandomelement(@nucleotides);

use File::Path;

print "\n\t MUTATION OF DNA \n\n";

print "ENTER THE FILENAME OF THE DNA SEQUENCE:= ";

$dnafilename = <STDIN>;

chomp $dnafilename;

unless ( open(DNAFILE, $dnafilename) )

print "Cannot open file \"$dnafilename\"\n\n";

goto h;

my $DNA = <DNAFILE>;

close DNAFILE;

Department of Computer Science Page 40


OUTPUT:

Department of Computer Science Page 41


RESULT: The program is executed and verified successfully

Department of Computer Science Page 42


Ex. No – 10 SIMULATE DNA MUTATIONS

AIM: Write a Script to Simulate DNA Mutations

ALGORITHM:

Step 1: Start the Program.


Step 2: Create a new folder in Perl Folder.
Step 3: Open Notepad and type the program.
Step 4: Save the program as 1DNASequence.pl in the folder which is created
in Perl.
Step 5: Run the program in Command Prompt as Perl 1DNASequence.pl.
Step 6: Stop the program.

Steps Using Tools:


1. Search NCBI in the Google.
2. Select the nucleotide sequence link.
3. Enter the scientific name of the organism and search. Bioperl
Programming Language
4. Select the FASTA link.
5. Copy the sequence and save the sequence in the notepad.

Department of Computer Science Page 43


PROGRAM

#! /usr/bin/perl -w
# Storing DNA in a variable, and printing it out
# First we store the DNA in a variable called $DNA
$DNA = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';
# Next, we print the DNA onto the screen
print $DNA;
# Finally, we'll specifically tell the program to exit.
Exit;

Department of Computer Science Page 44


OUTPUT

RESULT: The program is executed and verified successfully

Department of Computer Science Page 45


Ex. No – 11 PROTEIN SEQUENCE GENERATION

Aim: Write a Script for Protein Sequence generation

Steps Using Tools:


1. Search Expasy tool in theGoogle.
2. Click the Proteomicscolumn.
3. Under the databases, click UniProtKBlink.
4. Copy the protein sequence in the textfile.

Department of Computer Science Page 46


Department of Computer Science Page 47
Department of Computer Science Page 48
RESULT: Thus the protein sequence is generated successfully.

Department of Computer Science Page 49


Ex. No – 12 CONCATENATING DNA FRAGMENTS TRANSCRIPTION :
DNA TO RNA

AIM: To write a script to transcription of DNA to RNA using bioperl.

ALGORITHM:

STEP 1: Start the process.

STEP 2: Using bio::seq and bio::seqIO get the DNA sequence.

STEP 3: Declare DNA1 and DNA2 to store DNA fragments and print.

STEP 4: Transcribe the DNA to RNA by substituting all T’s with U’s .

STEP 5: Print the RNA onto the screen.

STEP 6: Stop the process.

Department of Computer Science Page 50


PROGRAM:
#!/usr/bin/perl -w

# Transcribing DNA into RNA

print"Transcribing DNA into RNA\n";

print"*************************\n\n";

# The DNA

$DNA = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';

# Print the DNA onto the screen

print "Here is the starting DNA:\n\n";

print "$DNA\n\n";

# Transcribe the DNA to RNA by substituting all T's with U's.

$RNA = $DNA;

$RNA =~ s/T/U/g;

# Print the RNA onto the screen

print "Here is the result of transcribing the DNA to RNA:\n\n";

print "$RNA\n";

# Exit the program.

exit;

Department of Computer Science Page 51


OUTPUT:

RESULT: The program is executed and verified successfully

Department of Computer Science Page 52

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy