PHP Code Snippets and HTML Documents, Assignments of Biology

Various php code snippets and html documents, including code for preventing multiple form submissions, integrating functions using the trapezoidal rule, extracting numbers from arrays, and finding mutations in sequences. Each code snippet is accompanied by a brief explanation and instructions for use.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-hlg-1
koofers-user-hlg-1 🇺🇸

9 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
November 26, 2008
bitmap processing
Here is the PHP code for changing colors in a bitmap file. This particular example uses a
grayscale file, but it is applicable to full-color files, too.
<?php
// Modify contents of a .bmp file.
$inFile="sky05NovGray.bmp";
// Change this path to a local folder for which you have write
permission.
$outFile="c:/Documents and Settings/All
Users/Documents/phpout/skyout.bmp";
//$inFile="sky05Nov.bmp";
//$inFile="sky05NovBW.bmp";
//$inFile="sky05Nov16color.bmp";echo "File Name: ".$inFile."<br />";
echo filesize($inFile)."<br />";
$in=fopen($inFile,'r');
// Read header.
$c=array();
while ($i<14) {
$c[$i]=ord(fgetc($in));
echo $c[$i]." ";
$i++;
}
echo "<br />";
// Calculate file size.
$size=$c[4]*65536+$c[3]*256+$c[2];
echo "File size = ".$size." bytes.<br />";
$offset=$c[10];
echo "Offset to start of image = ".$offset."<br />";
$i=0;
while ($i<40) {
$c[$i]=ord(fgetc($in));
echo $c[$i]." ";
$i++;
}
echo "<br />Bits per pixel = ".$c[14]."<br />";
// Go back to beginning of file -- first close it...
fclose($in);
// Get rows and columns.
$cols=$c[5]*256+$c[4];
$rows=$c[9]*256+$c[8];
echo "This image has ".$rows." rows and ".$cols." columns.<br />";
// Total number of pixels.
$N=$rows*$cols;
// ... and then re-open it along with output file.
$in=fopen($inFile,'r');
$out=fopen($outFile,'w');
// Skip to start of image data.
for ($i=0; $i<$offset; $i++) {
$ch=fgetc($in);
fwrite($out,$ch,1);
}
// Now read image bytes.
for ($n=1; $n<=$N; $n++) {
// Read colors, blue, green, red.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download PHP Code Snippets and HTML Documents and more Assignments Biology in PDF only on Docsity!

November 26, 2008

bitmap processing

Here is the PHP code for changing colors in a bitmap file. This particular example uses a

grayscale file, but it is applicable to full-color files, too.

";_ echo filesize ( $inFile ). "
"
; $in = fopen ( $inFile , 'r' ); // Read header. $c = array (); while ( $i < 14 ) { $c [ $i ]= ord ( fgetc ( $in )); echo $c [ $i ]. " " ; $i ++; } echo "
"
; // Calculate file size. $size = $c [ 4 ]
65536 + $c [ 3 ]
256 + $c [ 2 ]; echo "File size = ". $size. " bytes.
"
; $offset = $c [ 10 ]; echo "Offset to start of image = ". $offset. "
"
; $i = 0 ; while ( $i < 40 ) { $c [ $i ]= ord ( fgetc ( $in )); echo $c [ $i ]. " " ; $i ++; } echo "
Bits per pixel = "
. $c [ 14 ]. "
"
; // Go back to beginning of file -- first close it... fclose ( $in ); // Get rows and columns. $cols = $c [ 5 ]* 256 + $c [ 4 ]; $rows = $c [ 9 ]* 256 + $c [ 8 ]; echo "This image has ". $rows. " rows and ". $cols. " columns.
"
; // Total number of pixels. $N = $rows * $cols ; // ... and then re-open it along with output file. $in = fopen ( $inFile , 'r' ); $out = fopen ( $outFile , 'w' ); // Skip to start of image data. for ( $i = 0 ; $i < $offset ; $i ++) { $ch = fgetc ( $in ); fwrite ( $out , $ch , 1 ); } // Now read image bytes. for ( $n = 1 ; $n <= $N ; $n ++) { // Read colors, blue, green, red.

for ( $i = 0 ; $i <= 2 ; $i ++) { $c [ $i ]= fgetc ( $in ); // Here is where you can modify pixel colors. This statement turns on // the red gun to maximum brightness for every pixel. if ( $i == 0 ) $c [ $i ]= chr ( 255 ); fwrite ( $out , $c [ $i ], 1 ); } } echo "Total number of pixels written (rows x columns) = ". $n. "
"
; echo "Here is the last set of three pixels:
"
; echo ord ( $c [ 0 ]). " ". ord ( $c [ 1 ]). " ". ord ( $c [ 2 ]). "
"
; fclose ( $in ); fclose ( $out ); ?>

November 19, 2008

Code to prevent multiple form submission in “account keeper” program.

For reasons I don’t understand, I can’t get the code in your PHP book about

preventing multiple submissions to work with this homework problem. Here is an HTML

document that will work. You have to click on the Reset button before you can submit

another transaction.

**

** Transaction Amount: $
Deposit **** _ _ Withdrawal
Date (mm/dd/yyyy): **

**

October 23, 2008

for ( i = 0 ; i < n ; i ++) { if ( S. charAt ( i )!= "," ) s += S. charAt ( i ); else { // Save the number when you find a comma. A [ j ]= parseFloat ( s );; j ++; s = "" ; } }

October 22, 2008

Last night, the group working on the “blood types” document wanted to be able to

change the background color of their document based on some criterion calculated from a

user’s blood type. Here’s how to do it.

Colors are set by assigning decimal values between 0 and 255 to the red, green,

and blue “guns” (in reference to cathode ray tube technology). You can specify these

values any way you like, but you must then convert them into a hexadecimal string that

can be used to specify the color. For example, a totally black background is #000000 (all

guns off), a white background is #ffffff (all guns at maximum), and a bright fuschia

background is #ff00ff (blue gun turned off). Here’s a function that generates a string

based on three numerical inputs for red, green, and blue guns. The toString() method

converts a number to a string. By default, this method assumes you want the number

represented as a base-10 (decimal) string. If you specify toString(16), the

assumption is that you want a hexadecimal representation of the number, which is what

we need here.

I can’t guarantee that this will work with all browsers. I searched briefly online

for code to do this task, but I didn’t find anything right away so I wrote my own. There

may be other solutions, too, but this one seems to work fine.

**

**

** **

Group project from 21 October: Find all occurrences of a substring in a string.

Untitled

Enter your mutation here:

Enter your sequence here:

Group project from 21 October: blood types

** **

** ** A+ ** ** A- ** ** B+ ** ** B- ** ** AB+ ** ** AB- ** ** O+ ** ** O- **



** Blood type that you can donate to: **

** % of Population with that type of blood: **
** Blood type that you can recieve blood from:


% of Population with that type of blood: **

**

Returning multiple values from a function by storing them in an array.

This is another version of the Document 6.5, circlestuff.htm, in which the area

and circumference are stored in an array, to be returned to the main document. This is

often a better way to return multiple output values than passing a form to the function.

circlestuff2.htm

**

** Circle Stuff **

function circleStuff** ( r ) { var r = parseFloat ( r ); var circle =[]; circle [ 0 ]=( Math. PI * r * r ). toFixed ( 4 ); circle [ 1 ]=( 2 .* Math. PI * r ). toFixed ( 4 ); return circle ; } **

** Circle Stuff ** ** Enter radius, then press tab key or click on "area" box.

radius (cm):


area (cm **** 2 **** ):


circumference(cm): **

**

Parsing strings:

Here are a couple of examples for manipulating strings. The first example could

represent a start at code that extracts numbers from a string of characters entered into a

type=”text” box, with numbers separated by commas. For example, if you entered

your goal would be to extract the four real numbers and store them in an array.

Example 1:

**

**

**** home **

**

frameDescription.htm

**

1"> ** How this image was created. **

** This image was created in Windows' Paint program. **** Click here to return. **

**

frameMain.htm

**

** A simple frameset document **

**

gossip.htm

**

** Gossip Column **

document**. write ( "This document last modified on " + document. lastModified + "." ) **

** This is where gossip goes!!! **

** Can you **** believe **** that...??? **

**

homeFrame.htm

**

** Gossip Column ****

** document**. write ( "This document last modified on " + document. lastModified + "." ) **

** This is where gossip goes!!! **

** Can you **** believe **** that...??? **

**

photoGallery.htm

**

** A picture gallery **

** Here is the picture gallery. **

**

frame.gif

picture.gif