A simple counter written in php and a simple counter written in php

Source: Internet
Author: User

A simple counter written in php and a simple counter written in php

Php has extremely powerful image processing capabilities and can be used to dynamically generate web Images easily.
Here is a simple counter made of php.

1. Overall Thinking:
Records the number of previous visitors in a text file. When a webpage is accessed
Read the previous number of visitors, add 1 to get the latest number of visitors, and format the number
The standard format is used to call the image processing function, output the number as an image, and then return the new access number.
It is written to the file that records the number of visitors.

2. function description used by the Program:
A. Related File Operations:
A. open the file:
Function prototype: int fopen (string filename, string mode );
Returned result: if the file is successfully opened, the function returns the file stream pointer; otherwise, FALSE (0) is returned ).
Parameter description:
String filename -- name of the file to be opened, which must be in the string format.
For example, "zzm.txt" and ".. \ zzm.txt.
String mode: The method to open a file. It must be a character.
'R' in read-only mode. The file Pointer Points to the beginning of the file.
'R + ', readable and writable. The file Pointer Points to the beginning of the file.
'W', write-only, the file Pointer Points to the beginning of the file, cut the file length to 0,
If the file does not exist, create a file.
'W + ', readable and writable. The file Pointer Points to the beginning of the file and cut the file length to 0,
If the file does not exist, create a file.
'A', append form (only writable), the file Pointer Points to the end of the file, if
File does not exist.
'A + ', readable and writable. The file Pointer Points to the end of the file. If the file does not exist,
Will try to create a file.
Example: Open "zzm.txt" in the current directory in read-only mode"
$ Fp = fopen ("zzm.txt", "r ");

B. close the file:
Function prototype: int fclose (int fp );
Returned results: 1 is returned for success, and 0 is returned for failure.
Parameter description: int fp is the file stream pointer returned by the fopen function.
Example: Use fopento open the zzm.txt file.
Fclose ($ fp );

C. Read files:
Function prototype: string fgets (int fp, int length );
Return result: a string Of length-1 is returned. If the string ends at the End Of the File, EOF (End Of File) is returned)

Parameter description:
Int fp-the file stream pointer to read data, which is a value returned by the fopen function.
Int length -- number of characters read. The actual number of characters read is length-1.
Example: Read 9 characters from $ fp
$ Str1 = fgets ($ fp, 10 );

D. Write a file:
Function prototype: int fputs (int fp, string str, int [length]);
Returned results: Same as fclose
Parameter description:
Int fp-the file stream pointer to write information, which is a value returned by the fopen function.
String str -- string of the file to be written.
Int length -- the write length. Optional. If length is not provided, the entire string is written,
Otherwise, write length characters.
Example: write "0000000001" to $ fp"
Fput ($ fp, "0000000001 ");

B. Related string functions:
A. Calculate the string length:
Function prototype: int strlen (string str );
Return result: returns the length of the string.
Parameter description:
String str -- string to calculate the length
Example: Calculate the length of the string "000000000"
$ Str2 = "000000000 ";
$ Len2 = strlen ($ str );

B. String addition: It is simplest. use one to connect the two strings.
Example: add $ str1 and $ str2
$ Str = $ str1. $ str2

C. Related graphic functions:
A. Create an image:
Function prototype: int imagecreate (int x_size, int y_size );
Return result: returns an empty image ID (ImageID) x y pixels)
Parameter description: x_size and y_size indicate the width and height of the newly created image (in pixels)
Example: Create an empty 88*31 pixel image
$ ImageID = imagecreate (88, 31 );

B. assign a color to the image:
Function prototype: int imagecolorallocate (int im, int red, int green, int blue );
Return result: returns an RGB color identification number to the image ($ im ).
Description of parameters: int im image identification number
Int red, green, and blue are the components of red, green, and blue respectively. The value ranges from 0 to 255.
Example: assign a identification number $ im to the image, which is $ white in white color and RGB (255,255,255) in white color)
$ White = imagecolorallocate ($ im, 255,255,255 );
C. Fill the image with color:
Function prototype: int imagefill (int im, int x, int y, int col );
Return result: 1 is returned successfully; otherwise, 0 is returned.
Parameter description: int im, Image Identification Number
Int x, int y, fill the color from the (x, y) coordinates of the image
(0, 0) indicates the upper left corner of the image
Int col, the identification number of the color
Example: Fill in black from the upper left corner of the image (that is, the entire image) (The imagecolorallocate function has been used.
Defines the black color identification number as $ black ).
Imagefill ($ im, 0, 0, $ black );

D. Calculate the image width:
Function prototype: int imagesx (int im );
Returned result: the width of the returned image, in pixels)
Parameter description: int im, the identification number of the image.
Example: Calculate the width of the image $ im
$ Px = imagesx ($ im );

Http://php.662p.com/thread-363-1-1.html

 

Php writes a simple calculator for addition, subtraction, multiplication, and division.

As you modified:

<Script type = "text/javascript">
Function showu3 (num1, num2, num3)
{
Document. getElementById ('u1'). value = num1;
Document. getElementById ('u2 '). value = num2;
Document. getElementById ('u3'). value = num3;
}
</Script>

<? Php
If (! Empty ($ _ GET ["fuhao"])
{
$ Fuhao = $ _ GET ["fuhao"];
$ U1 = $ _ GET ["u1"];
$ U2 = $ _ GET ["u2"];
$ U3 = $ _ GET ["u3"];
Switch ($ fuhao)
{
Case "+ ":
$ U3 = $ u1 + $ u2;
Break;
/* Subtract, multiply, and divide anything. Write it by yourself.
Case "-"
*/
}
?>
<Script type = "text/javascript"> showu3 (<? Php echo $ u1. ','. $ u2. ','. $ u3?> ); </Script>
<? Php
}
?>
<Form action = "test. php" method = "get">
Number 1 <input type = "text" name = "u1" size = "5" value = <? Php echo isset ($ u1 )? "$ U1": ""?> >
<Select name = "fuhao">
<Option> + </option>
<Option>-</option>
<Option> x </option>
<Option>/</option>
<Option >%</option>
</Select>
Number 2 <input type = "text" name = "u2" size = "5" value = <? Php echo isset ($ u2 )? "$ U2": ""?> >
= <Input type = "text" name = "u3" I ...... the remaining full text>

Use PHP to program a web calculator to implement simple arithmetic operations

Save the following content in PHP format.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">
<Html xmlns = "www.w3.org/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> four Arithmetic Operations </title>
</Head>

<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<P>
<Input name = "y" type = "text" id = "y" size = "10"/>
<Select name = "y0" id = "y0">
<Option> + </option>
<Option>-</option>
<Option> * </option>
<Option>/</option>
</Select>
<Input name = "y1" type = "text" id = "y1" size = "10"/>
<Input type = "submit" name = "Submit" value = "computing"/>
</P>
<P> </p>
<P> </p>
</Form>
<? Php
Function make_safe ($ variable ){
$ Variable = addslashes (trim ($ variable ));
Return $ variable;
}
$ Y0 = make_safe ($ _ REQUEST ["...... the remaining full text >>>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.