PHP functions: Uncommon but very useful PHP functions
Source: Internet
Author: User
Functions are such a powerful source of PHP, but many PHP functions are not fully exploited. Here, we give you a brief description of 10 unusual, but very useful, functions.
1. Sys_getloadavg ()
SYS_GETLOADAVT () can obtain the system load condition. The function returns an array of three elements, each representing the average load of the system in the past 1, 5, and 15 minutes, respectively. Rather than letting the server down because it is overloaded, it is better to actively die a script when the system is heavily loaded, Sys_getloadavg () is used to help you achieve this function. Unfortunately, this function is not valid under Windows.
2. Pack ()
Pack () Converts the 32-bit 16-digit string returned by MD5 () to a 16-bit binary string, which saves storage space.
3. Cal_days_in_month ()
Cal_days_in_month () can return the number of days in the specified month.
4. _ ()
WordPress developers can often see this function, as well as _e (). These two functions are identical and can be used in conjunction with the GetText () function to realize the multi-language of the website. Refer to the relevant sections of the PHP manual for details.
5. Get_browser ()
Is it good to look at what the user's browser can do before sending the page? Get_browser () can get the user's browser type, as well as browser-supported features, but first you need a Php_browscap.ini file to make reference files for functions.
Note that this function is based on the general nature of the browser's functionality. For example, if a user turns off browser support for JavaScript, the function is not aware of this. However, the function is accurate in determining the browser type and OS platform.
6. Debug_print_backtrace ()
This is a debugging function that can help you find logic errors in your code. To understand this function, just look at an example:
$a = 0;
function Iterate () {
Global $a;
if ($a < 10)
Recur ();
echo $a. “, “;
}
function recur () {
Global $a;
$a + +;
How about did I get here?
echo "\n\n\n";
Debug_print_backtrace ();
if ($a < 10)
Iterate ();
}
Iterate ();
# OUTPUT:
#0 recur () called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate () called at [c:\htdocs\php_stuff\index.php:25]
#0 recur () called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate () called at [c:\htdocs\php_stuff\index.php:21]
#2 recur () called at [C:\htdocs\php_stuff\index.php:8]
#3 iterate () called at [c:\htdocs\php_stuff\index.php:25]
#0 recur () called at [C:\htdocs\php_stuff\index.php:8]
#1 iterate () called at [c:\htdocs\php_stuff\index.php:21]
#2 recur () called at [C:\htdocs\php_stuff\index.php:8]
#3 iterate () called at [c:\htdocs\php_stuff\index.php:21]
#4 recur () called at [C:\htdocs\php_stuff\index.php:8]
#5 iterate () called at [c:\htdocs\php_stuff\index.php:25]
7. Metaphone ()
This function returns the Metaphone value of the word, the same pronunciation of the word has the same Metaphone value, that is, this function can help you determine whether two words are the same pronunciation.
8. Natsort ()
Natsort () can arrange an array in a natural sort order, just look at an example:
$items = Array ("Apples", "5 apples", "apples", apples "
);
Normal sorting:
Sort ($items);
Print_r ($items);
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