"PHP Programming Fastest understand" eighth: PHP Inspiration and summary _php Foundation

Source: Internet
Author: User
Tags php programming
At the same time, there are a number of functions that can be implemented in a variety of ways, which require flexible application. Only remember these functions, to develop a dynamic web site, and only more practice, the entire site development once, can be skilled in the next development, only to find their own deficiencies and improve.

Many methods can be improved, such as this counter:

Instance 24 counter
Copy Code code as follows:

<?php
Counter
function Countx ($file = "Count.dat") {
if (file_exists ($file)) {
$FP =fopen ($file, "R");
$numx =fgets ($FP, 10);
Fclose ($FP);
$numx + +;
The above four lines of code can be replaced by an expression: $numx =file_get_contents ($file) +1;
}
else{
$NUMX = 1;}
File_put_contents ($file, $NUMX);//When the file does not exist, this function automatically creates the file and automatically turns the argument into a string write.
Echo $numx;
/* The entire function body can be replaced by two expressions: File_exists ($file)? file_put_contents ($file, file_get_contents ($file) +1): File_put_contents ($ File, "1"); ReadFile ($file);
*/
}
Function call
Countx ();
?>

There are many ways to achieve this, let's think about it.

Finally, this example is used to debug the calculation of the use of the code to run the time, the unit is seconds to five decimal output, equivalent to search engine time, commonly used in SQL optimization, code as follows:

Instance 25 calculates the time it takes to run the code, optimizing the Code
Copy Code code as follows:

<?php
$ftime =microtime ();
Countx ()//Here is the code that calculates the time it takes to run, which is the function that invokes the previous example.
$ftime =number_format ((Microtime ()-$ftime), 5);
Echo $ftime;
?>

I this tutorial basically takes the example mainly, rarely tells, these code is not difficult, the function is also selects carefully, my goal is can use quickly, for instance can handle Chinese, if I copy the book to say can only handle English function, that what use? Or I take out the function you can't use, it's a waste of time.

I do not speak simple grammar, but I believe that through representative examples of practice, the grammar and the basis are not a problem. There is this tutorial is my first, intermediate people, the development of practical sites enough. I will also have a higher level of tutorials, such as sock, XML, ZIP, PDF, mail and other class library development, and write their own cms. I strive to understand the fastest, not to be faster understand it!

Thank you again, this junior class tutorial on this to here, now more busy, we can also go to my Site www.kuphp.com stroll, learn from each other!

If you look more tired, here are packaged PDF and doc version of the download address http://www.jb51.net/books/32601.html

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.