


15 hours----from modifying programs to making your own programs_PHP Tutorial
This article is original and copyrighted by the man who was knocked down by the wind. It comes from the forum of www.ipp.org. Please keep this information for online reprinting. Please contact me for non-online reprinting. It is not easy for individual webmasters to write things by themselves. , and to give me the courage and motivation to continue writing, please do not delete this description when reprinting. This article is the first one, and I will find time to write out the rest one after another.
Many friends’ understanding of PHP has been stuck in modifying other people’s programs for a long time. Because they can be modified, they are too lazy to make progress. Or when they bought a book and read it, they found that PHP has so many functions. I was scared to death when I saw the function library. Wait. I belong to the latter. This article is specifically for lazy people who spend time learning PHP, but want to make something by themselves.
Later, I joined a minor class in school. The teacher taught in class and I had to take the final exam. So, I was forced to write simple code by myself.
So , this article is for friends who can modify the HTML in the program, but cannot modify the program structure. They have basic programming foundation, that is: being able to understand if and else. It is enough, or everyone with the same foundation is suitable. Experts can go Open. Until now, I still need to check the manual with common functions, and I still write garbage code.
Okay, let's talk less, let's enter the first stage
Friends who can modify programs are considered web masters in the eyes of their classmates. If I start talking about what variables are, it will inevitably waste your time. I myself am a text collector, so we can start with Start by analyzing a part of a program in detail. The program is very simple, with only a few simple judgments. I will write the description of the program in unparalleled detail.
Quote:
If you don't understand something, please tell me and I will correct it as soon as possible, or email me. My email address is rainboy#tom.com. Please don't send me spam. I have been spammed now. It’s very annoying
Let’s start by analyzing the simplest counter
The function of the counter is: refresh the page once, the number increases by one.
The program is as follows
Code:
[Copy to clipboard]
$datafile="data.txt";
$fp1=fopen($datafile,"r");
$num=fgets($fp1,10);
$num =trim($num);
fclose($fp1);
echo "You are the ".$num." guest";
$fp2=fopen($datafile,"w");
$num=$num+1;
fputs($fp2,"$num");
fclose($fp2);
?>
Here is a detailed explanation of the procedure
Code:
[Copy to clipboard]
/* PHP files are wrapped with ?> or . When the server executes, the content in the tag can be taken out and executed.* /
/*
Set the data storage file, because the variables in php are stored in the server memory and disappear immediately after execution, so we need to use text to save the number of visitors who browse , we use data.txt, we can adjust it according to the situation. There is a $ sign in front of the variables in php, so everything with the $ sign is a variable. Create the data file manually, write 1 in it, and then save it
*/
$datafile="data.txt";
/*This step is to open the file, using the fopen() function, which is the function to open the file. It accepts two parameters, one is the file name and the other is the opening method. For example, if you use "r" to open in this program, it will be opened in read-only mode. $fp1 is a handle. What is a handle? Just like when you use a toothbrush , by using the handle of the toothbrush to operate the toothbrush to make your teeth clean. Then $fp1 is like the handle of the toothbrush. PHP controls the data storage file data.txt by operating the handle of $fp1. This step operates To sum it up in one sentence: use the fopen function to open the data file, and pass the handle of the opened file to $fp1. If you still have questions about the use of the fopen function after reading this, please refer to this site's PHP online manual http: //www.ipp.org/manual/function.fopen.html
How to use the fopen function
*/
$fp1=fopen($datafile,"r");
/*
To summarize the use of this statement in one sentence: open the file to read data
Use the function: fgets("handle", "number of bytes to read the file content");, and get the result The purpose of reading the file content is to read the handle $fp1. The $num obtained in this sentence is the first 10 bytes in the file.
*/
$num=fgets($fp1,10);
/*
trim(); function is used to remove spaces before and after a string, for example,
$num="123 ";
trim($num) is 123 ;
*/
$num=trim($num);
/*
The fclose function closes the file. The parameter required by the fclose function is $fp1
*/
fclose($fp1);
/*
Everyone knows how to use the echo function, which is equivalent to print(); The meaning of output on a web page
Connect strings and variables Use "." between spaces so that you can print variables in php. The use of the connection symbol "." is very important. To be clear, please refer to the PHP online manual of this site http://www.ipp.org/manual/language The part about string concatenation in .operators.string.html
.
*/
echo "You are the ".$num." guest";
/ *
Use fopen to open the file. The opening method is "w". The file opened with the w method is in write-only mode. If the file does not exist, the file will be created. If the file exists, the file content will be cleared first.Then write, the function of this sentence is to open the file, and then pass the handle to $fp2.
*/
$fp2=fopen($datafile,"w");
/*Browse Increase the number by one*/
$num=$num+1;
/*Write the number after increasing by one to the file. The method of using fputs is very simple. The first parameter is the file handle, and the second parameter is the file handle. Each parameter is the content to be written. If you have any questions about how to use the fputs function, please refer to http://www.ipp.org/manual/function.fputs.html*/
fputs($fp2,"$num");
/*Close the open file*/
fclose($fp2);
?>
(Source: www.ipp.org)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

1. First open DingTalk. 2. Open the group chat and click the three dots in the upper right corner. 3. Find my nickname in this group. 4. Click to enter to modify and save.

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

An email signature is important to demonstrate legitimacy and professionalism and includes contact information and company logo. Outlook users often complain that signatures disappear after restarting, which can be frustrating for those looking to increase their company's visibility. In this article, we will explore different fixes to resolve this issue. Why do my Microsoft Outlook signatures keep disappearing? If this is your first time using Microsoft Outlook, make sure your version is not a trial version. Trial versions may cause signatures to disappear. Additionally, the version architecture should also match the version architecture of the operating system. If you find that your email signature disappears from time to time in Outlook Web App, it may be due to

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

Douyin Blue V certification is the official certification of a company or brand on the Douyin platform, which helps enhance brand image and credibility. With the adjustment of corporate development strategy or the update of brand image, the company may want to change the name of Douyin Blue V certification. So, can Douyin Blue V change its name? The answer is yes. This article will introduce in detail the steps to modify the name of the enterprise Douyin Blue V account. 1. Can Douyin Blue V change its name? You can change the name of Douyin Blue V account. According to Douyin’s official regulations, corporate Blue V certified accounts can apply to change their account names after meeting certain conditions. Generally speaking, enterprises need to provide relevant supporting materials, such as business licenses, organization code certificates, etc., to prove the legality and necessity of changing the name. 2. What are the steps to modify the name of corporate Douyin Blue V account?

Win10 Sleep Time Modification Tips Revealed As one of the currently widely used operating systems, Windows 10 has a sleep function to help users save power and protect the screen when not using the computer. However, sometimes the default sleep time does not meet the needs of users, so it is particularly important to know how to modify the Win10 sleep time. This article will reveal the tips for modifying the sleep time of Win10, allowing you to easily customize the system’s sleep settings. 1. Modify Win10 sleep time through “Settings” First, the simplest fix

When publishing products on the Xianyu platform, users can customize the geographical location information of the product according to the actual situation, so that potential buyers can more accurately grasp the specific location of the product. Once the product is successfully put on the shelves, there is no need to worry if the seller's location changes. The Xianyu platform provides a flexible and convenient modification function. So when we want to modify the address of a published product, how do we modify it? This tutorial guide will provide you with a detailed step-by-step guide. I hope it can help. Everyone! How to modify the release product address in Xianyu? 1. Open Xianyu, click on what I published, select the product, and click Edit. 2. Click the positioning icon and select the address you want to set.
