Home >Backend Development >PHP Tutorial >Some overlooked PHP functions (organized)
From: http://www.gracecode.com/posts/3013.html
You really don’t need to know, in fact, the PHP we are familiar with still has many good things that we have not discovered yet. When I saw this article, I burst into tears several times. I highly recommend it and I will sort it out myself.
sys_getloadavg()
This function returns the load average information of the current system (of course Not applicable under Windows), for detailed documentation, please refer to the relevant documentation of PHP. There is a sample code in the document, and you can basically see its use.
cal_days_in_month()
This function can directly return the number of days in the specified month, such as
I can guarantee that you have implemented a function with similar functions yourself :^)
_()
Well, this is indeed a PHP function (it may also be the shortest PHP built-in function).
Friends who have written WordPress skins will know the functions
You can use gettext to write multi-language applications. Now you may be interested in how to write locale files, but this is no longer the focus of this article. For more information, you can move here.
get_browser()
To be honest, I burst into tears when I saw this function. With this function, you no longer have to analyze the string
More information can be found here. Before using this function, you may need a browscap.ini configuration file, I believe you can handle it.
debug_print_backtrace()
In the past, to view the function call stack, I would use extensions such as xdebug. In fact, the PHP5 version has built-in related functions.
By the way, I’d like to share a little trick that’s “painful”. If you can’t remember the name of this function, you can use this code to achieve the same goal (it seems to be more reliable to remember that function):
natsort( )
This function is used for natural sorting, which everyone may need. Post the relevant document links and sample code
For the algorithm rules of natural sorting, you can refer to the documentation here.
glob()
The function of this function also makes people cry. Let’s not talk about the function and go directly to the example code
Compared with you already understand the purpose of this function, then we can have more "playing methods" ”, for example, display the directory ( via ):
Of course, you can also consider using the SPL extension for file recursion.
Supplementary by 神仙 :
PHP Filter
If you are still validating the string regularly, then it is really "Out". Since PHP5.2 version, PHP Filter is built-in The module is used to specifically verify whether emails, URLs, etc. are legitimate. Sample code:
Since it is a new module, there are still many traps, such as
But this does not affect us from trying. For more information about PHP Filter, I believe I can write another article.
Finally, I lament that PHP is actually a long-lasting tool. If we are not careful, we will tragically reinvent the wheel. Therefore, take a look at the PHP documentation from time to time and you will learn something new every time.
The above has introduced some neglected PHP functions (organized), including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.