PHP programming the fastest to understand lecture 8: PHP inspiration and summary

  • 2020-03-31 21:19:20
  • OfStack

At the same time, there are many functions can be implemented in a variety of ways, which needs to be applied flexibly. Only by memorizing these functions can you develop dynamic websites; Only more practice, the development of the entire site once, in order to skillfully carry out the next development, to find their own shortcomings and improve.

Many methods can be improved, such as this counter:

Instance 24 counter
 
<?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 writes the argument to a string.
echo $numx; 
 
} 
//A function call
countx(); 
?> 

There are a lot of ways to do this, so let's think about it.

The last example is the time used to calculate the code running during debugging. The unit is seconds and output in five decimal places, which is equivalent to the search time of the search engine and is often used for optimization of SQL. The code is as follows:

Example 25 calculates the time the code takes to run and optimizes the code
 
<?php 
$ftime=microtime(); 
countx();//Here is the code to calculate the elapsed time, which is the function that calls the previous example.
$ftime=number_format((microtime()-$ftime),5); 
echo $ftime; 
?> 

This tutorial is mainly based on examples, rarely described, the code is not difficult, the function is also carefully selected, my purpose is to be able to quickly use, for example, can handle Chinese, if I copy the book said that can only handle English functions, what is the use? Or if I take a function that you don't use, that's a waste of time.

I'm not going to talk about simple grammar, but I'm sure you'll be able to use both grammar and basics with typical examples. Also, this tutorial is for beginners and intermediates, so it's enough to develop a practical website. I'll do more advanced tutorials on sock, XML, ZIP, PDF, Mail, and other library development, as well as writing my own CMS. I strive to understand as soon as possible, no also want to understand faster!

Thank you again, this is the beginning of the intermediate tutorial here, now more busy, you can also to my website (link: http://www.kuphp.com) browse, learn from each other!

If you are tired, here is a package of PDF and doc version of the download address (link: #)

Related articles: