15 hours ---- from modifying programs to your own programs _ PHP Tutorial

Source: Internet
Author: User
Tags php online
15 hours-from modifying the program to some of your own programs. This article is an original article by the wind, with copyright. this is a forum from www.iphp.org. please keep this information for Internet reprinting. for non-network reprint, contact me. it is not easy for a webmaster to write his own things. This article is also an original article by the wind, with copyright. this is a forum from www.iphp.org. please keep this information for Internet reprinting. for non-network reprint, contact me. it is not easy for my webmaster to write things on his own. in order to give me the courage and motivation to continue writing, please do not delete this description during reprinting. this is the first article, and I will find time to write future things.


Many of my friends have long-term knowledge of php and stay on modifying other people's programs. they are lazy and progressive because they can be modified. or when I bought a book and read it, I found that php functions were so invincible that I was stunned when I saw the function library. and so on. I myself belong to the latter. this article is intended for lazy people who spend time learning php but want to do something on their own.

Later, I attended a secondary school. the teacher told me that I had to take the final exam, so I was forced to write simple code by myself.

Therefore, this article is intended for users who can modify the html of a program, but cannot modify the program structure. it has the basic program Foundation: can understand if and else. enough, or suitable for people with the same foundation. experts can go away. so far, I still need to check the manual for using common functions and write junk code again.

Okay, let's get down to the first stage.


Friends who can modify the program are regarded as top-notch characters on the webpage. if I start from what is a variable, it will inevitably delay your time. I am also engaged in text collection, so we can start with a detailed analysis of a part of the program. the program is very simple. there are only a few simple judgments. I will write the program description in Invincible detail.

Quote, please do not send me any spam. I am bored with spam.
Next we will start by profiling a simplest counter

The counter function is to refresh the page once and add one to the number.
The procedure 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 );
?>
The following Code explains the program in detail: [Copy to clipboard]
/* Php files are all used Or Wrapped, the server can retrieve the content in the label for execution during execution .*/

/*
Variable, we can adjust according to the situation. php variables are preceded by a $ symbol. Therefore, all $ symbols are variables. manually create a data file, write 1 in it, and then save
*/
$ Datafile = "data.txt ";


/* This step is to open the file and use the fopen () function. the fopen function is the function to open the file. this function accepts two parameters: the file name and the open method. for example, in this program, "r" is used to open it in read-only mode. $ fp1 is a handle. what is a handle? The. in this step, you can use the fopen function to open a data file and pass the handle of the opened file to $ fp1. if you read this, you still have questions about how to use the fopen function, please refer to this site php online manual http://www.iphp.org/manual/function.fopen.html
How to use fopen functions
*/
$ Fp1 = fopen ($ datafile, "r ");


/*
To summarize the usage of this statement in one sentence: open a file and read data
Function: fgets ("handle", "number of bytes to read the file content"); the result is to read the file content by reading the handle $ fp1. $ num is the first 10 bytes in the file.
*/
$ Num = fgets ($ fp1, 10 );


/*
Trim (); function is used to remove spaces before and after the string, such
$ 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 );

/*

We all know how to use the echo function, which is equivalent to print ();
Use ". "to print the variables in php. connection symbol ". "usage is very important. to be clear, please refer to the site's php online manual http://www.iphp.org/manual/language.operators.string.html
Section about string connection.
*/
Echo "you are the". $ num. "guest ";


/*
Use fopen to open a file. the open method is "w". the file opened by w is in write-only mode. if the file does not exist, create the file. if the file exists, first, the file content is cleared. Then write, the purpose of this sentence is to open the file, and then pass the handle to $ fp2.
*/
$ Fp2 = fopen ($ datafile, "w ");

/* Add one view count */
$ Num = $ num + 1;

/* It is easy to use fputs to write numbers after adding one. The first parameter is the file handle, and the second parameter is the content to be written, if you have any questions about how to use the fputs function, refer to http://www.iphp.org/manual/function.fputs.html#/ in the php online manual on this site */
Fputs ($ fp2, "$ num ");

/* Close the opened file */
Fclose ($ fp2 );
?>

(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.