


PHP built-in function example tutorial, built-in function example tutorial_PHP tutorial
Jul 12, 2016 am 08:51 AMphp内置函数实例教程,内置函数实例教程
有大小写转换相关函数
strtolower()
strtoupper()
ucfirst()
ucword()
文本html标签处理函数
nl2br()
htmllentities()
htmlspecialchars()
stripslashes()
strip_tags()
number_format()
strrev()
md5()
//转换成小写
$a='www.jb51.net';
echo strtolower($a);
//结果:www.jb51.net
//转换成大写
$a='www.jb51.net';
echo strtoupper($a);
//结果:WWW.jb51.net
//首字母大写
$a='www.jb51.net';
echo ucfirst($a);
//结果:Www.jb51.net
//每个单词首字母大写
$a='i love you';
echo ucword($a);
//结果:I Love You
/*
提示:大家都知道大小写,认为小写和大写有区别吗,但是为什么要区分大小写呢
在win系统下php大小写不严格 但是在linux系统下就严禁拉 大小写不能乱写
比如
在自动加载类的时候
function _autoload($className){
include strtolower($className).'.class.php';
}
$obj= new MyClass;
这样就加载myclass.class.php
因为文件名常是小写那么必须转换小写
?>
*/
//nl2br把空格转换成实体
因为一般在浏览器里显示的换行都是
例如在表单留言本里必须要转换不然折行不成功 再多的空格都任务是一个空格
$a='
i
love
you
';
echo $a;
echo nl2br($a);
结果1:i love you
结果2:
i
love
you
//表单提交如果你不进行html标签处理那么就会直接显示样式或者js代码直接运行
/*
当你输入
www.jb51.net
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
Others, if you check the source code, you will know that have been replaced by and it will be displayed in the page prototype.
There is another important point if you do not process some copied articles Having tag styles will disrupt your page layout and may conflict with css
I won’t talk about the opposite usage of htmllentities() function and htmlspecialchars()
When you need to keep that tag, you can use the strip_tags() function
echo strip_tags($_GET['title'],'
') ;
The submission result is that if you check the source code, you will find that is gone
/*
Add the input i love 'jb51';
The submission result is i love 'jb51' with the backslash escaped
So what should I do if I want to output the original text?
It can be used This php function stripslashes()
unescapes
echo stripslashes($_GET['title']);
The result is i love 'jb51';
What if it contains html tags like this
i love 'jb51'
What should I do if I want prototype output? I can use two functions combined. I have Said
echo htmlspecialchars(stripslashes($_GET['title']));
Result: i love 'jb51'
*/
//number_format() This function is a formatting currency function. Different countries have different habits, so the required currency display is different. For example, Chinese money in the mall is usually formatted like this.
Use commas to separate thousandths and keep the number. The digit is called the 'decimal point'
The usage of this function is very simple
number_format($money, how many decimal points to keep, 'what to separate the decimal point', 'what to separate the thousandths')
$price ='123465789.233';
echo number_format($money,2,',','.');
Result: 123.465.789, 23
echo number_format($money,2,'.', ',');//Chinese style
Result: 123,465,789.23
//strrev() reverses the string
$str='http://www.jb51.net';
echo strrev($str);
Result: moc.tenwii. www//:ptth
//md5 is encryption. Username and password must be encrypted to prevent hackers.
$a='admin';
echo $b= md5($a);
Built-in functions are functions provided by PHP. Many functions can be achieved through these functions.
is_int, is_integer, is_long, determine whether the variable is an integer
is_float, is_double, is_real, determine whether the variable is a floating point type
is_bool determines whether the variable is of Boolean type
is_string determines whether the variable is a string
is_array determines whether the variable is an array type
is_resource determines whether the variable is a resource type
is_object determines whether the variable is an object
is_null determines whether the variable is null
$_SERVER['SCRIPT_NAME'] returns /mantis/test.php, relative path;
__FILE__ returns the absolute path of the file D:Projectsmantistest.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS ']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI is used to specify the page to be accessed
$GLOBALS is a global combination array containing all variables. The name of the variable is the key of the array.
explode uses a string to split another string and returns a string array
implode uses a character to link the array elements into a string
$_SERVER['SERVER_NAME'] The host name of the server where the current script is located
$_SERVER['HTTP_HOST'] domain name
$_SERVER['SERVER_ADDR'] IP address of the server where the current script is located
trim removes the blank characters at the beginning and end of the string
basename returns the file name part
dirname returns the directory part
krsort — sorts the array in reverse order by key name
set_time_limit() sets the maximum execution time of the script
time() returns the current unix timestamp
is_string() determines whether the variable is a string
is_bool
is_Inteter
is_float
strtotime -- Parse the date and time description of any English text into a UNIX timestamp
file_exists checks whether the file or directory exists
fopen() opens the specified file or URL
feof() determines whether the file pointer is at the end
fgets() reads a line from the file pointer
trim() removes spaces before and after a line
strlen() returns the length of the string
str_replace
isset
str_replace( "
get_include_path Get the current include_path
count() returns the length of the array, non-array returns 1
substr(string string,int start [int length]) Returns the length of the string starting from the position specified by start
$_SERVER['LOCAL_ADDR'] Used on IIS7 to obtain the server IP address
$_SERVER['REMOTE_ADDR' ] The IP address of the browser user
array_pad — pads the array with values to the specified length
memory_get_usage() Returns the amount of memory allocated to PHP
spl_autoload_register registers the __autoload() function
ob_get_contents() Return the contents of the output buffer
strtolower() Convert uppercase letters to lowercase letters
extension_loaded('zlib') Find out whether the extension is loaded
ini_get Returns the value of the configuration item in php.ini
ini_set sets the value of the configuration item in php.ini, ini_set("memory_limit",'256M'); only takes effect during script execution. The value is reset after the script is executed
PHP_EOL PHP line terminator
preg_replace performs a regular expression replacement
preg_match(string pattern, string subject [, array matches [, int flags]]) -- Regular expression matching
htmlspecialchars Convert special characters to HTML entities
ceil() Rounding method
floor() Rounding method
round() Rounding method
10 Very Useful Uncommon PHP Built-in Functions
1. sys_getloadavg()
sys_getloadavt() can obtain the system load status. This function returns an array containing three elements, each element representing the system's average load over the past 1, 5, and 15 minutes.
Rather than letting the server crash due to excessive load, it is better to actively die a script when the system load is very high. sys_getloadavg() is used to help you achieve this function. Unfortunately, this function is not valid under Windows.
2. pack()
Pack() can convert the 32-bit hexadecimal string returned by md5() into a 16-bit binary string, which can save storage space.
3. cal_days_in_month()
cal_days_in_month() can return the number of days in the specified month.
4. _()
WordPress developers often see this function, as well as _e(). These two functions have the same function and can be used in combination with the gettext() function to achieve multilingualization of the website. For details, please refer to the relevant parts of the PHP manual.
5. get_browser()
Wouldn’t it be nice to see what the user’s browser can do before sending the page? get_browser() can get the user's browser type and the functions supported by the browser, but first you need a php_browscap.ini file to serve as a reference file for the function.
It should be noted that this function’s judgment of browser functions is based on the general characteristics of this type of browser. For example, if the user has turned off JavaScript support in the browser, the function has no way of knowing this. However, this function is still very accurate in determining browser type and OS platform.
6. debug_print_backtrace()
This is a debugging function that can help you find logical errors in the code. To understand this function, let’s look at an example:
-
- $a = 0;
- function iterate() {
- global $a;
- if( $a
- recur();
- echo $a . “, “;
- }
- function recur() {
- global $a;
- $a ;
- //how did I get here?
- echo “nnn”;
- debug_print_backtrace();
- if( $a
- iterate();
- }
- iterate();
- ?>
OUTPUT:
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:21]
#4 recur() called at [C:htdocsphp_stuffindex.php:8]
#5 iterate() called at [C:htdocsphp_stuffindex.php:25]
OUTPUT: #0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex .php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur( ) called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C:htdocsphp_stuffindex.php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8] #1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur() called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C :htdocsphp_stuffindex.php:21]#4 recur() called at [C:htdocsphp_stuffindex.php:8]#5 iterate() called at [C:htdocsphp_stuffindex.php:25] td>
7. metaphone()
This function returns the metaphone value of the word. Words with the same pronunciation have the same metaphone value, which means this function can help you determine whether the pronunciation of two words is the same. But it is invalid for Chinese.
8. natsort()
natsort() can arrange an array in natural sorting. Let’s take a look at an example:
-
- $items = array(“100 apples”, “5 apples”, “110 apples”, “55 apples”);
- // normal sorting:
- sort($items);
- print_r($items);
- ?>
Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )
Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )
9. levenshtein()
Levenshtein() tells you the "distance" between two words. It tells you how many letters you need to insert, replace, and delete if you want to change one word into another. Let’s look at an example:
-
$dictionary = array(“php”, “javascript”, “css”); -
$word = “japhp”; -
$best_match = $dictionary[0]; -
$match_value = levenshtein($dictionary[0], $word); -
foreach($dictionary as $w) { -
$value = levenshtein($word, $w); -
if( $value
$best_match = $w; -
$match_value = $value; -
} -
} -
echo ”Did you mean the ‘$best_match’ category?”; -
?>
10. glob()
glob() will make you feel stupid using opendir(), readdir() and closedir() to find files.
-
foreach (glob(“*.php”) as $file) { -
echo “$filen”; -
} -
?>
http://www.bkjia.com/PHPjc/1128378.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1128378.htmlTechArticlephp built-in function example tutorial, the built-in function example tutorial has case conversion related functions strtolower() strtoupper() ucfirst( ) ucword() text html tag processing function nl2br() htmllentitie...
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
Others, if you check the source code, you will know that have been replaced by and it will be displayed in the page prototype.
There is another important point if you do not process some copied articles Having tag styles will disrupt your page layout and may conflict with css
I won’t talk about the opposite usage of htmllentities() function and htmlspecialchars()
When you need to keep that tag, you can use the strip_tags() function
echo strip_tags($_GET['title'],'
') ;
The submission result is that if you check the source code, you will find that is gone
/*
Add the input i love 'jb51';
The submission result is i love 'jb51' with the backslash escaped
So what should I do if I want to output the original text?
It can be used This php function stripslashes()
unescapes
echo stripslashes($_GET['title']);
The result is i love 'jb51';
What if it contains html tags like this
i love 'jb51'
What should I do if I want prototype output? I can use two functions combined. I have Said
echo htmlspecialchars(stripslashes($_GET['title']));
Result: i love 'jb51'
*/
//number_format() This function is a formatting currency function. Different countries have different habits, so the required currency display is different. For example, Chinese money in the mall is usually formatted like this.
Use commas to separate thousandths and keep the number. The digit is called the 'decimal point'
The usage of this function is very simple
number_format($money, how many decimal points to keep, 'what to separate the decimal point', 'what to separate the thousandths')
$price ='123465789.233';
echo number_format($money,2,',','.');
Result: 123.465.789, 23
echo number_format($money,2,'.', ',');//Chinese style
Result: 123,465,789.23
//strrev() reverses the string
$str='http://www.jb51.net';
echo strrev($str);
Result: moc.tenwii. www//:ptth
//md5 is encryption. Username and password must be encrypted to prevent hackers.
$a='admin';
echo $b= md5($a);
Built-in functions are functions provided by PHP. Many functions can be achieved through these functions.
is_int, is_integer, is_long, determine whether the variable is an integer
is_float, is_double, is_real, determine whether the variable is a floating point type
is_bool determines whether the variable is of Boolean type
is_string determines whether the variable is a string
is_array determines whether the variable is an array type
is_resource determines whether the variable is a resource type
is_object determines whether the variable is an object
is_null determines whether the variable is null
$_SERVER['SCRIPT_NAME'] returns /mantis/test.php, relative path;
__FILE__ returns the absolute path of the file D:Projectsmantistest.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS ']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI is used to specify the page to be accessed
$GLOBALS is a global combination array containing all variables. The name of the variable is the key of the array.
explode uses a string to split another string and returns a string array
implode uses a character to link the array elements into a string
$_SERVER['SERVER_NAME'] The host name of the server where the current script is located
$_SERVER['HTTP_HOST'] domain name
$_SERVER['SERVER_ADDR'] IP address of the server where the current script is located
trim removes the blank characters at the beginning and end of the string
basename returns the file name part
dirname returns the directory part
krsort — sorts the array in reverse order by key name
set_time_limit() sets the maximum execution time of the script
time() returns the current unix timestamp
is_string() determines whether the variable is a string
is_bool
is_Inteter
is_float
strtotime -- Parse the date and time description of any English text into a UNIX timestamp
file_exists checks whether the file or directory exists
fopen() opens the specified file or URL
feof() determines whether the file pointer is at the end
fgets() reads a line from the file pointer
trim() removes spaces before and after a line
strlen() returns the length of the string
str_replace
isset
str_replace( "
get_include_path Get the current include_path
count() returns the length of the array, non-array returns 1
substr(string string,int start [int length]) Returns the length of the string starting from the position specified by start
$_SERVER['LOCAL_ADDR'] Used on IIS7 to obtain the server IP address
$_SERVER['REMOTE_ADDR' ] The IP address of the browser user
array_pad — pads the array with values to the specified length
memory_get_usage() Returns the amount of memory allocated to PHP
spl_autoload_register registers the __autoload() function
ob_get_contents() Return the contents of the output buffer
strtolower() Convert uppercase letters to lowercase letters
extension_loaded('zlib') Find out whether the extension is loaded
ini_get Returns the value of the configuration item in php.ini
ini_set sets the value of the configuration item in php.ini, ini_set("memory_limit",'256M'); only takes effect during script execution. The value is reset after the script is executed
PHP_EOL PHP line terminator
preg_replace performs a regular expression replacement
preg_match(string pattern, string subject [, array matches [, int flags]]) -- Regular expression matching
htmlspecialchars Convert special characters to HTML entities
ceil() Rounding method
floor() Rounding method
round() Rounding method
10 Very Useful Uncommon PHP Built-in Functions
1. sys_getloadavg()
sys_getloadavt() can obtain the system load status. This function returns an array containing three elements, each element representing the system's average load over the past 1, 5, and 15 minutes.
Rather than letting the server crash due to excessive load, it is better to actively die a script when the system load is very high. sys_getloadavg() is used to help you achieve this function. Unfortunately, this function is not valid under Windows.
2. pack()
Pack() can convert the 32-bit hexadecimal string returned by md5() into a 16-bit binary string, which can save storage space.
3. cal_days_in_month()
cal_days_in_month() can return the number of days in the specified month.
4. _()
WordPress developers often see this function, as well as _e(). These two functions have the same function and can be used in combination with the gettext() function to achieve multilingualization of the website. For details, please refer to the relevant parts of the PHP manual.
5. get_browser()
Wouldn’t it be nice to see what the user’s browser can do before sending the page? get_browser() can get the user's browser type and the functions supported by the browser, but first you need a php_browscap.ini file to serve as a reference file for the function.
It should be noted that this function’s judgment of browser functions is based on the general characteristics of this type of browser. For example, if the user has turned off JavaScript support in the browser, the function has no way of knowing this. However, this function is still very accurate in determining browser type and OS platform.
6. debug_print_backtrace()
This is a debugging function that can help you find logical errors in the code. To understand this function, let’s look at an example:
-
- $a = 0;
- function iterate() {
- global $a;
- if( $a
- recur();
- echo $a . “, “;
- }
- function recur() {
- global $a;
- $a ;
- //how did I get here?
- echo “nnn”;
- debug_print_backtrace();
- if( $a
- iterate();
- }
- iterate();
- ?>
OUTPUT:
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:21]
#4 recur() called at [C:htdocsphp_stuffindex.php:8]
#5 iterate() called at [C:htdocsphp_stuffindex.php:25]
OUTPUT: #0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex .php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur( ) called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C:htdocsphp_stuffindex.php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8] #1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur() called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C :htdocsphp_stuffindex.php:21]#4 recur() called at [C:htdocsphp_stuffindex.php:8]#5 iterate() called at [C:htdocsphp_stuffindex.php:25] td>
7. metaphone()
This function returns the metaphone value of the word. Words with the same pronunciation have the same metaphone value, which means this function can help you determine whether the pronunciation of two words is the same. But it is invalid for Chinese.
8. natsort()
natsort() can arrange an array in natural sorting. Let’s take a look at an example:
-
- $items = array(“100 apples”, “5 apples”, “110 apples”, “55 apples”);
- // normal sorting:
- sort($items);
- print_r($items);
- ?>
Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )
Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )
9. levenshtein()
Levenshtein() tells you the "distance" between two words. It tells you how many letters you need to insert, replace, and delete if you want to change one word into another. Let’s look at an example:
-
$dictionary = array(“php”, “javascript”, “css”); -
$word = “japhp”; -
$best_match = $dictionary[0]; -
$match_value = levenshtein($dictionary[0], $word); -
foreach($dictionary as $w) { -
$value = levenshtein($word, $w); -
if( $value
$best_match = $w; -
$match_value = $value; -
} -
} -
echo ”Did you mean the ‘$best_match’ category?”; -
?>
10. glob()
glob() will make you feel stupid using opendir(), readdir() and closedir() to find files.
-
foreach (glob(“*.php”) as $file) { -
echo “$filen”; -
} -
?>
http://www.bkjia.com/PHPjc/1128378.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1128378.htmlTechArticlephp built-in function example tutorial, the built-in function example tutorial has case conversion related functions strtolower() strtoupper() ucfirst( ) ucword() text html tag processing function nl2br() htmllentitie...
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入
www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:
www.jb51.net
Others, if you check the source code, you will know that have been replaced by and it will be displayed in the page prototype.
There is another important point if you do not process
I won’t talk about the opposite usage of htmllentities() function and htmlspecialchars()
When you need to keep that tag, you can use the strip_tags() function
echo strip_tags($_GET['title'],'
/* //number_format() This function is a formatting currency function. Different countries have different habits, so the required currency display is different. For example, Chinese money in the mall is usually formatted like this. //strrev() reverses the string //md5 is encryption. Username and password must be encrypted to prevent hackers. time() returns the current unix timestamp is_string() determines whether the variable is a string is_bool is_Inteter is_float strtotime -- Parse the date and time description of any English text into a UNIX timestamp file_exists checks whether the file or directory exists fopen() opens the specified file or URL feof() determines whether the file pointer is at the end fgets() reads a line from the file pointer trim() removes spaces before and after a line strlen() returns the length of the string preg_replace performs a regular expression replacement preg_match(string pattern, string subject [, array matches [, int flags]]) -- Regular expression matching 1. sys_getloadavg() sys_getloadavt() can obtain the system load status. This function returns an array containing three elements, each element representing the system's average load over the past 1, 5, and 15 minutes. Rather than letting the server crash due to excessive load, it is better to actively die a script when the system load is very high. sys_getloadavg() is used to help you achieve this function. Unfortunately, this function is not valid under Windows. Pack() can convert the 32-bit hexadecimal string returned by md5() into a 16-bit binary string, which can save storage space. cal_days_in_month() can return the number of days in the specified month. WordPress developers often see this function, as well as _e(). These two functions have the same function and can be used in combination with the gettext() function to achieve multilingualization of the website. For details, please refer to the relevant parts of the PHP manual. Wouldn’t it be nice to see what the user’s browser can do before sending the page? get_browser() can get the user's browser type and the functions supported by the browser, but first you need a php_browscap.ini file to serve as a reference file for the function. It should be noted that this function’s judgment of browser functions is based on the general characteristics of this type of browser. For example, if the user has turned off JavaScript support in the browser, the function has no way of knowing this. However, this function is still very accurate in determining browser type and OS platform. 6. debug_print_backtrace() This is a debugging function that can help you find logical errors in the code. To understand this function, let’s look at an example: 7. metaphone() This function returns the metaphone value of the word. Words with the same pronunciation have the same metaphone value, which means this function can help you determine whether the pronunciation of two words is the same. But it is invalid for Chinese. 8. natsort() natsort() can arrange an array in natural sorting. Let’s take a look at an example:
9. levenshtein()
10. glob()
') ;
The submission result is that if you check the source code, you will find that
Add the input i love 'jb51';
The submission result is i love 'jb51' with the backslash escaped
So what should I do if I want to output the original text?
It can be used This php function stripslashes()
unescapes
echo stripslashes($_GET['title']);
The result is i love 'jb51';
What if it contains html tags like this
i love 'jb51'
What should I do if I want prototype output? I can use two functions combined. I have Said
echo htmlspecialchars(stripslashes($_GET['title']));
Result: i love 'jb51'
*/
Use commas to separate thousandths and keep the number. The digit is called the 'decimal point'
The usage of this function is very simple
number_format($money, how many decimal points to keep, 'what to separate the decimal point', 'what to separate the thousandths')
$price ='123465789.233';
echo number_format($money,2,',','.');
Result: 123.465.789, 23
echo number_format($money,2,'.', ',');//Chinese style
Result: 123,465,789.23
$str='http://www.jb51.net';
echo strrev($str);
Result: moc.tenwii. www//:ptth
$a='admin';
echo $b= md5($a);
__FILE__ returns the absolute path of the file D:Projectsmantistest.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS ']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI is used to specify the page to be accessed
$GLOBALS is a global combination array containing all variables. The name of the variable is the key of the array.
explode uses a string to split another string and returns a string array
implode uses a character to link the array elements into a string
$_SERVER['SERVER_NAME'] The host name of the server where the current script is located
$_SERVER['HTTP_HOST'] domain name
$_SERVER['SERVER_ADDR'] IP address of the server where the current script is located
trim removes the blank characters at the beginning and end of the string
basename returns the file name part
dirname returns the directory part
krsort — sorts the array in reverse order by key name
set_time_limit() sets the maximum execution time of the script
isset
str_replace( "
get_include_path Get the current include_path
count() returns the length of the array, non-array returns 1
substr(string string,int start [int length]) Returns the length of the string starting from the position specified by start
$_SERVER['LOCAL_ADDR'] Used on IIS7 to obtain the server IP address
$_SERVER['REMOTE_ADDR' ] The IP address of the browser user
array_pad — pads the array with values to the specified length
memory_get_usage() Returns the amount of memory allocated to PHP
spl_autoload_register registers the __autoload() function
ob_get_contents() Return the contents of the output buffer
strtolower() Convert uppercase letters to lowercase letters
extension_loaded('zlib') Find out whether the extension is loaded
ini_get Returns the value of the configuration item in php.ini
ini_set sets the value of the configuration item in php.ini, ini_set("memory_limit",'256M'); only takes effect during script execution. The value is reset after the script is executed
PHP_EOL PHP line terminator
ceil() Rounding method
floor() Rounding method
round() Rounding method
10 Very Useful Uncommon PHP Built-in Functions
2. pack()
3. cal_days_in_month()
4. _()
5. get_browser()
OUTPUT: #0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex .php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8]#1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur( ) called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C:htdocsphp_stuffindex.php:25]#0 recur() called at [C:htdocsphp_stuffindex.php:8] #1 iterate() called at [C:htdocsphp_stuffindex.php:21]#2 recur() called at [C:htdocsphp_stuffindex.php:8]#3 iterate() called at [C :htdocsphp_stuffindex.php:21]#4 recur() called at [C:htdocsphp_stuffindex.php:8]#5 iterate() called at [C:htdocsphp_stuffindex.php:25] td>
OUTPUT:
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:25]
#0 recur() called at [C:htdocsphp_stuffindex.php:8]
#1 iterate() called at [C:htdocsphp_stuffindex.php:21]
#2 recur() called at [C:htdocsphp_stuffindex.php:8]
#3 iterate() called at [C:htdocsphp_stuffindex.php:21]
#4 recur() called at [C:htdocsphp_stuffindex.php:8]
#5 iterate() called at [C:htdocsphp_stuffindex.php:25]
Outputs:
Outputs:
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )
# Array
# (
# [0] => 100 apples
# [1] => 110 apples
# [2] => 5 apples
# [3] => 55 apples
# )
natsort($items);
print_r($items);
# Outputs:
# Array
# (
# [2] => 5 apples
# [3] => 55 apples
# [0] => 100 apples
# [1] => 110 apples
# )

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools