Table of Contents
A simple counter written in php, a simple counter written in php
Write a simple calculator for addition, subtraction, multiplication and division in php, but I lost my ability halfway through writing it
Use PHP to program a web calculator to implement simple four arithmetic operations
Home Backend Development PHP Tutorial A simple counter written in php, writing a simple counter in php_PHP tutorial

A simple counter written in php, writing a simple counter in php_PHP tutorial

Jul 13, 2016 am 10:21 AM
calculator

A simple counter written in php, a simple counter written in php

php has extremely powerful image processing capabilities, and it can be used to easily dynamically generate web images.
The following is a simple counter made using php.

1. General idea:
Record the number of past visitors in a text file. When the web page is visited, open the file
and read out the number of past visitors, and add 1. Get the latest number of visitors, format the number into the
standard format, then call the image processing function to output the number into a picture, and then write the new number of visitors back to
to record the number of visitors. in the file.

2. Function description used by the program:
A. Related file operations:
a. Open file:
Function prototype: int fopen(string filename, string mode);
Return result: If the file is opened successfully, the function returns the file stream pointer, otherwise it returns FALSE(0).
Parameter description:
string filename -- the name of the file to be opened, must be in the form of a string.
For example, "zzm.txt", "..zzm.txt", etc.
String mode -- The way to open the file, must be in character form.
'r', read-only form, 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 form, the file pointer points to the file at the beginning, truncate the file length to 0,
If the file does not exist, an attempt will be made to create the file.
'w+', readable and writable, the file pointer points to the beginning of the file, truncate the file length to 0,
If the file does not exist, it will try to create the file.
'a', append form (can only be written), the file pointer points to the end of the file, if the file
does not exist, an attempt will be made to create the file.
'a+', readable and writable, the file pointer points to the end of the file, if the file does not exist,
will try to create the file.
Example: Open "zzm.txt" under the current directory in read-only mode
$fp = fopen("zzm.txt", "r");

b. Close the file:
Function prototype: int fclose(int fp);
Return result: 1 is returned on success, 0 is returned on failure
Parameter description: int fp is the file stream pointer returned by the fopen function.
Example: Close the zzm.txt file just opened with fopen
fclose($fp);

c. Read the file:
Function prototype: string fgets(int fp, int length ; File stream pointer, the value returned by the fopen function
int length -- the 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 file:
Function prototype: int fputs(int fp, string str, int [length]);
Return result : Same as fclose
Parameter description:
int fp -- the file stream pointer to write information, the value returned by the fopen function
string str -- the string to be written to the file.
int length -- the length to write, optional. If length is not provided, the entire string will be written.
Otherwise, length characters will be written.
Example: Write "0000000001" to $fp
fput($fp, "0000000001");

B. Related string functions:
a. Calculate the length of the string:
Function prototype: int strlen(string str);
Return result: Return the length of the string
Parameter description:
String str -- the string whose length is to be calculated
Example: Calculate the string length of "000000000"
$str2 = "000000000";
$len2 = strlen($str);

b. Addition: Easiest However, use a . to connect the two strings.
Example: Add $str1 and $str2
$str = $str1.$str2

C. Related graphics functions:
a. New image:
Function prototype : int imagecreate(int x_size, int y_size);
Return result: Return an empty image identification number (ImageID) of X*Y pixel size
Parameter description: x_size, y_size are the width and height of the new image respectively ( In pixels)
Example: Create a new empty image of 88*31 pixel size
$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: Return an RGB color identification number to the image ($im)
Parameter description: int im image identification number Int Red, Green, and Blue are the weight of three colors of red, green and blue, respectively. )
$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: Return 1 if successful, otherwise return 0
Parameter description: int im, the identification number of the image
int x, int y, start filling the color from the (x, y) coordinates of the image
(0,0) represents the upper left corner of the image
int col, the identification number of the color
Example: Fill in black starting from the upper left corner of the image (that is, the entire image) (has been defined with the imagecolorallocate function
The color identification number for black is $black).
imagefill($im, 0, 0, $black);

d. Calculate the width of the image:
Function prototype: int imagesx(int ​​im);
Return result: return image The width (unit is pixel)
Parameter description: int im, the identification number of the image.
Example: Calculate the width of image $im
$px = imagesx($im);

Detailed description;

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

Write a simple calculator for addition, subtraction, multiplication and division in php, but I lost my ability halfway through writing it

Modified it according to your suggestion:


}
?>


Number 1 < ;input type="text" name="u1" size="5" value= >

Number 2 >
= >

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

Save the following content into PHP format and it will be OK





Four arithmetic operations



< ;form id="form1" name="form1" method="post" action="">










function make_safe($variable) {
$variable = addslashes(trim($variable));
return $variable;
}
$y0=make_safe($_REQUEST["...the rest of the text>>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/861531.htmlTechArticleA simple counter written in php, php writes a simple counter php has extremely powerful image processing capabilities, you can use it It's easy to dynamically generate web images. Here is a way to use p...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What key is ac on the calculator? What key is ac on the calculator? Feb 24, 2023 am 10:19 AM

The ac key on the calculator is the "all clear" key. The full English name of ac is "All Clear", which means "all clear key"; pressing the ac key means clearing the values ​​in all registers; during number input, the first press Pressing the ac key will clear all values ​​except the memory contents.

What is e in the calculator What is e in the calculator Oct 19, 2022 am 11:23 AM

The e in the calculator represents the power of 10, which means the exponent with base 10. For example, 1.99714E13 is equal to 19971400000000; expressing a number in the form of a multiplied by the nth power of 10 is called scientific notation. Notation: When we want to mark or operate something larger or smaller with a large number of digits, we can use scientific notation to avoid wasting a lot of space and time.

Teach you how to open the win10 calculator Teach you how to open the win10 calculator Jul 12, 2023 pm 11:21 PM

The win10 system has many powerful functions, which attract many netizens to download, install and use it. There are also many practical gadgets, such as the win10 calculator tool. Some netizens still don’t know how to open the Win10 calculator. Let me teach you how to open the Win10 calculator. Method 1: Search in the Start menu 1. On the Windows 10 system desktop, click the "Start/Calculator" menu item. 2. You can open the calculator window of Windows 10. Method 2: Open Cortana Search 1. On the Windows 10 desktop, click the "Cortana Search" icon in the lower left corner of the taskbar. 2. Enter the keyword "calculator" in the pop-up menu to search, and click the calculator menu item in the search results.

What is a calculator without storage function? What is a calculator without storage function? Dec 29, 2020 am 10:59 AM

Calculator without storage function refers to scientific calculator; scientific calculator is a type of electronic calculator that can perform operations such as exponentiation, square root, exponent, logarithm, trigonometric function, statistics, etc., also known as Function calculator; a calculator generally consists of a calculator, a controller, a memory, a keyboard, a display, a power supply, and some optional peripherals and electronic accessories.

An efficient Fibonacci sequence calculator written in PHP An efficient Fibonacci sequence calculator written in PHP Mar 21, 2024 am 10:06 AM

Efficient Fibonacci sequence calculator: PHP implementation of Fibonacci sequence is a very classic mathematical problem. The rule is that each number is equal to the sum of the previous two numbers, that is, F(n)=F(n -1)+F(n-2), where F(0)=0 and F(1)=1. When calculating the Fibonacci sequence, it can be implemented recursively, but performance problems will occur as the value increases. Therefore, this article will introduce how to write an efficient Fibonacci using PHP

How to implement a simple calculator function using JavaScript? How to implement a simple calculator function using JavaScript? Oct 27, 2023 pm 02:51 PM

How to implement a simple calculator function using JavaScript? Calculator is one of the commonly used tools in our daily life. It can be used to perform simple mathematical operations. Today, we will use JavaScript to implement a simple calculator function. In this article, I'll show you how to write code in JavaScript to implement basic math operations and calculator interfaces. First, we need to create an HTML file that contains a text for displaying the results of the operation.

How to convert currency on Mac system calculator - How to convert currency on Mac system calculator How to convert currency on Mac system calculator - How to convert currency on Mac system calculator Mar 18, 2024 pm 03:58 PM

Friends, do you know how to convert currency on Mac system calculator? Today I will explain how to convert currency on Mac system calculator. If you are interested, please come and take a look with me. I hope it can help you. Step 1: Open the Mac system calculator, click Convert on the menu bar. Step 2: In the Conversion menu, click Currency. Step 3: After selecting the currency to convert, click the Convert button.

What key is ac on the calculator? What key is ac on the calculator? Aug 18, 2023 am 09:48 AM

The "AC" key on the calculator means "All Clear". Pressing the AC key will clear all inputs and operations in the calculator and reset the calculator to its initial state, which is equivalent to restarting a calculation.

See all articles