15 hours----from modifying the program to some of your own programs _php

Source: Internet
Author: User
This article belongs to the man who was blown down by the wind and owns the copyright. From the www.iphp.org Forum, the network reproduced please keep this information. Please contact me for non-network reprint. It is not easy for a personal webmaster to write something, and also for the courage and motivation to continue writing. Please do not delete this note at the time of reprint. This is the first article, I will find time to write the next thing.


Many friends of the understanding of PHP, long-term stay in the modification of other people's program, because can be modified so lazy to progress. Or when you buy a book to read, you find that PHP's functions are super-invincible, The library was stunned. I belong to the latter. This article is designed for lazy people who spend time learning PHP, but want to do something for themselves lazy.

To later, I took part in the school of a secondary class, the teacher lectures, the final exam to test, so, was forced to, incredibly able to write a simple code.

Therefore, this article is intended to modify the program in the HTML, but can not modify the program construction of friends, there is a Basic program foundation, is: can understand if and else. Enough, or have the same basis for the average person. The master can walk away. I still need to look up the manual to use the usual functions so far. Still write the garbage code again.

Okay, cut the crap, let's get to the first stage.


Can modify the program of friends, in the eyes of the students are the Web master level of the characters. If I start from what is the variable, it is unavoidable to delay your time. I am also a text collection, so we can start with a detailed analysis of a part of the program. The program is simple, with only a few simple judgments, I will write the description of the program in the invincible detail.

Quote: If you do not understand, please keep abreast tell me, I change in the first time, or email me, my e-mail address is rainboy#tom.com, please do not send spam to me, I have now been very annoying spam
Let's start by dissecting one of the simplest counters

The function of the counter is to refresh the page once and increase the number by one.
The procedure is as follows

Code:[copy to Clipboard] $datafile = "Data.txt";
$FP 1=fopen ($datafile, "R");
$num =fgets ($fp 1,10);
$num =trim ($num);
Fclose ($fp 1);
echo "You are the first". $num. " Guests ";
$FP 2=fopen ($datafile, "w");
$num = $num +1;
Fputs ($fp 2, "$num");
Fclose ($fp 2);
?>
The following is a detailed explanation of the program code:[copy to clipboard]
/* PHP files are used Or Wrapped, the server executes when it can take out the contents of the tag. */

/*
Set the data store file, because the variables in PHP are stored in the server memory, and disappear immediately after the execution, so we need to use text to save the number of visitors browsing, we use the data.txt, we can adjust according to the situation. The variables in PHP are preceded by a $ sign, so, A $ sign is a variable. Manually create a data file, write 1 in it, then save
*/
$datafile = "Data.txt";


/* This step is to open the file, using the fopen () function, the fopen function is the function that opens the file, the function accepts two parameters, one is the file name, and the other is open. For example, this program uses the "R" mode to open it in read-only mode. $FP 1 is a handle, what is a handle? Just like when you use a toothbrush, you use the handle of a toothbrush to make your teeth clean. So $fp1 is like that toothbrush handle, PHP by manipulating $FP1 This handle, to control data.txt this data store file. This step is summed up in a nutshell: Using the fopen function to open the data file and to pass the handle of the open file to $FP1, if you read here that you still have questions about how to use the fopen function, please refer to the PHP online manual of this site http://www.iphp.org/manual/function.fopen.html
How to use the fopen function
*/
$FP 1=fopen ($datafile, "R");


/*
A word to summarize the use of this statement: Open file read data
Use the function: Fgets ("Handle", "read the number of bytes of file content"), the result is to read the handle $FP1, to read the contents of the file. This sentence gets $num is the first 10 bytes in the file.
*/
$num =fgets ($fp 1,10);


/*
Trim (); The function is used to remove spaces before and after a string, such as
$num = "123";
Trim ($num) is 123;
*/
$num =trim ($num);

/*
The Fclose function closes the file, and the Fclose function requires a parameter of $FP1
*/
Fclose ($fp 1);

/*

How the Echo function is used everyone knows, the equivalent of print (); The meaning of the Web page output
Use "." Between the connection string and the variable so that you can print the variable in PHP. Connection symbol "." The use of this method is important. To be clear, please refer to the PHP online manual of this site http://www.iphp.org/manual/language.operators.string.html
The section about string joins in.
*/
echo "You are the first". $num. " Guests ";


/*
Open the file with fopen, open the method to "W", the file opened for the W method is write-only mode, if the file does not exist, then create the file, if the file exists, the contents of the file will be emptied first. Then write, the function of this sentence is to open the file, and then pass the handle to $FP2.
*/
$FP 2=fopen ($datafile, "w");

/* The number of views increased by one */
$num = $num +1;

/* will add a number later to write to the file fputs is simple, the first parameter is the file handle, the second parameter is to write the content, if you have doubts about the use of the fputs function, please refer to the PHP online manual http://www.iphp.org/ manual/function.fputs.html*/
Fputs ($fp 2, "$num");

/* Close the Open file */
Fclose ($fp 2);
?>

(Source: www.iphp.org)
  • 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.