php内置函数实例教程,内置函数实例教程
php内置函数实例教程,内置函数实例教程
有大小写转换相关函数
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
其他查看源码就知道已经被替换了成就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能css冲突
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'
');
提交结果是你查看源码 就会发现没有了
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a);
内置函数即PHP提供的函数,通过这些函数可以实现很多功能
is_int、is_integer、is_long,判断变量是否是整型
is_float、is_double、is_real,判断变量是否是浮点型
is_bool判断变量是否是布尔型
is_string判断变量是否是字符串
is_array判断变量是否是数组类型
is_resource判断变量是否是资源类型
is_object判断变量是否是对象
is_null判断变量是否是null
$_SERVER['SCRIPT_NAME'] 返回/mantis/test.php,相对路径;
__FILE__ 返回文件的绝对路径D:\Projects\mantis\test.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI 用来指定要访问的页面
$GLOBALS一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
explode 使用一个字符串分割另一个字符串 返回一个字符串数组
implode 使用一个字符将数组元素链接成字符串
$_SERVER['SERVER_NAME'] 当前脚本所在服务器的主机名
$_SERVER['HTTP_HOST'] 域名
$_SERVER['SERVER_ADDR'] 当前脚本所在服务器的IP地址
trim去除字符串首尾处的空白字符
basename 返回文件名部分
dirname 返回目录部分
krsort — 对数组按照键名逆向排序
set_time_limit()设置脚本最大执行时间
time() 返回当前的unix时间戳
is_string()判断变量是不是字符串
is_bool
is_Inteter
is_float
strtotime -- 将任何英文文本的日期时间描述解析为 UNIX 时间戳
file_exists 检查文件或目录存不存在
fopen()打开指定的文件或URL
feof()判断文件指针是否在末尾
fgets()从文件指针中读取一行
trim()去掉一行前后的空格
strlen()返回字符串的长度
str_replace
isset
str_replace( "\0", '', $t_self ) 将t_self中的\0替换成“”
strpos — 查找在字符串中首次出现的位置
$_SERVER['SERVER_SOFTWARE'] 服务器信息
realpath 返回规范化的绝对路径名
DIRECTORY_SEPARATOR 操作系统目录分隔符
PATH_SEPARATOR 在linux系统中是一个" : "号,Windows上是一个";"号
set_include_path 设置incldue_path
get_include_path 获取当前include_path
count() 返回数组长度,非数组返回1
substr(string string ,int start [int length]) 返回从start指定位置开始的长度的字符串
$_SERVER['LOCAL_ADDR'] IIS7上用来获取服务器IP地址
$_SERVER['REMOTE_ADDR'] 浏览器用户的IP地址
array_pad — 用值将数组填补到指定长度
memory_get_usage()返回分配给PHP的内存量
spl_autoload_register 注册__autoload()函数
ob_get_contents() Return the contents of the output buffer
strtolower() 将大写字母转换为小写字母
extension_loaded('zlib')找出扩展是否被加载
ini_get 返回php.ini中配置项的值
ini_set 设置php.ini中配置项的值 ,ini_set("memory_limit",'256M'); 只在脚本执行期间生效,脚本执行完成该值重置
PHP_EOL PHP行结束符
preg_replace 执行一个正则表达式的替换
preg_match(string pattern, string subject [, array matches [, int flags]]) -- 进行正则表达式匹配
htmlspecialchars Convert special characters to HTML entities
ceil() 进一法取整
floor() 舍去法取整
round()四舍五入法
非常有用的10个不常见PHP内置函数
1. sys_getloadavg()
sys_getloadavt()可以获得系统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。
与其让服务器因负载过高而宕掉,不如在系统负载很高时主动die掉一个脚本,sys_getloadavg()就是用来帮你实现这个功能的。 不过很遗憾,该函数在windows下无效。
2. pack()
Pack()能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。
3. cal_days_in_month()
cal_days_in_month()能够返回指定月份共有多少天。
4. _()
WordPress开发者经常能见到这个函数,还有_e()。这两个函数功能相同,与gettext()函数结合使用,能实现网站的多语言化。具体可参见PHP手册的相关部分介绍。
5. get_browser()
在发送页面前先看看用户的浏览器都能做些什么是不是挺好?get_browser()能获得用户的浏览器类型,以及浏览器支持的功能,不过首先你需要一个php_browscap.ini文件,用来给函数做参考文件。
要注意,该函数对浏览器功能的判断是基于该类浏览器的一般特性的。例如,如果用户关闭了浏览器对JavaScript的支持,函数无法得知这一点。但是在判断浏览器类型和OS平台方面,该函数还是很准确的。
6. debug_print_backtrace()
这是一个调试用的函数,能帮助你发现代码中的逻辑错误。要理解这个函数,还是直接看个例子吧:
-
- $a = 0;
- function iterate() {
- global $a;
- if( $a
- recur();
- echo $a . “, “;
- }
- function recur() {
- global $a;
- $a++;
- // how did I get here?
- echo “\n\n\n”;
- debug_print_backtrace();
- if( $a
- 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()
这个函数返回单词的metaphone值,相同读音的单词具有相同的metaphone值,也就是说这个函数可以帮你判断两个单词的读音是否相同。不过对中文就无效了。
8. natsort()
natsort()能将一个数组以自然排序法进行排列,直接看个例子吧:
-
- $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
# )
9. levenshtein()
Levenshtein()告诉你两个单词之间的“距离”。它告诉你如果想把一个单词变成另一个单词,需要插入、替换和删除多少字母。看个例子吧:
-
- $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()会让你觉得用opendir(), readdir()和closedir()来寻找文件非常蠢。
-
- foreach (glob(“*.php”) as $file) {
- echo “$file\n”;
- }
- ?>
一提交就出现是一号大字体
但是你原来是想要
www.jb51.net结果的
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:www.jb51.net
其他查看源码就知道已经被替换了成就会在页面原型显示
还有一点要主要 如果不处理有的复制的文章自身有标签样式就会打乱你的页面布局 可能css冲突
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'
');
提交结果是你查看源码 就会发现没有了
/*
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
//number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
//strrev()使字符串反倒过来
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
//md5就是加密 用户名密码必须要加密防止黑客
$a='admin';
echo $b= md5($a);
内置函数即PHP提供的函数,通过这些函数可以实现很多功能
is_int、is_integer、is_long,判断变量是否是整型
is_float、is_double、is_real,判断变量是否是浮点型
is_bool判断变量是否是布尔型
is_string判断变量是否是字符串
is_array判断变量是否是数组类型
is_resource判断变量是否是资源类型
is_object判断变量是否是对象
is_null判断变量是否是null
$_SERVER['SCRIPT_NAME'] 返回/mantis/test.php,相对路径;
__FILE__ 返回文件的绝对路径D:\Projects\mantis\test.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI 用来指定要访问的页面
$GLOBALS一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
explode 使用一个字符串分割另一个字符串 返回一个字符串数组
implode 使用一个字符将数组元素链接成字符串
$_SERVER['SERVER_NAME'] 当前脚本所在服务器的主机名
$_SERVER['HTTP_HOST'] 域名
$_SERVER['SERVER_ADDR'] 当前脚本所在服务器的IP地址
trim去除字符串首尾处的空白字符
basename 返回文件名部分
dirname 返回目录部分
krsort — 对数组按照键名逆向排序
set_time_limit()设置脚本最大执行时间
time() 返回当前的unix时间戳
is_string()判断变量是不是字符串
is_bool
is_Inteter
is_float
strtotime -- 将任何英文文本的日期时间描述解析为 UNIX 时间戳
file_exists 检查文件或目录存不存在
fopen()打开指定的文件或URL
feof()判断文件指针是否在末尾
fgets()从文件指针中读取一行
trim()去掉一行前后的空格
strlen()返回字符串的长度
str_replace
isset
str_replace( "\0", '', $t_self ) 将t_self中的\0替换成“”
strpos — 查找在字符串中首次出现的位置
$_SERVER['SERVER_SOFTWARE'] 服务器信息
realpath 返回规范化的绝对路径名
DIRECTORY_SEPARATOR 操作系统目录分隔符
PATH_SEPARATOR 在linux系统中是一个" : "号,Windows上是一个";"号
set_include_path 设置incldue_path
get_include_path 获取当前include_path
count() 返回数组长度,非数组返回1
substr(string string ,int start [int length]) 返回从start指定位置开始的长度的字符串
$_SERVER['LOCAL_ADDR'] IIS7上用来获取服务器IP地址
$_SERVER['REMOTE_ADDR'] 浏览器用户的IP地址
array_pad — 用值将数组填补到指定长度
memory_get_usage()返回分配给PHP的内存量
spl_autoload_register 注册__autoload()函数
ob_get_contents() Return the contents of the output buffer
strtolower() 将大写字母转换为小写字母
extension_loaded('zlib')找出扩展是否被加载
ini_get 返回php.ini中配置项的值
ini_set 设置php.ini中配置项的值 ,ini_set("memory_limit",'256M'); 只在脚本执行期间生效,脚本执行完成该值重置
PHP_EOL PHP行结束符
preg_replace 执行一个正则表达式的替换
preg_match(string pattern, string subject [, array matches [, int flags]]) -- 进行正则表达式匹配
htmlspecialchars Convert special characters to HTML entities
ceil() 进一法取整
floor() 舍去法取整
round()四舍五入法
非常有用的10个不常见PHP内置函数
1. sys_getloadavg()
sys_getloadavt()可以获得系统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。
与其让服务器因负载过高而宕掉,不如在系统负载很高时主动die掉一个脚本,sys_getloadavg()就是用来帮你实现这个功能的。 不过很遗憾,该函数在windows下无效。
2. pack()
Pack()能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。
3. cal_days_in_month()
cal_days_in_month()能够返回指定月份共有多少天。
4. _()
WordPress开发者经常能见到这个函数,还有_e()。这两个函数功能相同,与gettext()函数结合使用,能实现网站的多语言化。具体可参见PHP手册的相关部分介绍。
5. get_browser()
在发送页面前先看看用户的浏览器都能做些什么是不是挺好?get_browser()能获得用户的浏览器类型,以及浏览器支持的功能,不过首先你需要一个php_browscap.ini文件,用来给函数做参考文件。
要注意,该函数对浏览器功能的判断是基于该类浏览器的一般特性的。例如,如果用户关闭了浏览器对JavaScript的支持,函数无法得知这一点。但是在判断浏览器类型和OS平台方面,该函数还是很准确的。
6. debug_print_backtrace()
这是一个调试用的函数,能帮助你发现代码中的逻辑错误。要理解这个函数,还是直接看个例子吧:
-
- $a = 0;
- function iterate() {
- global $a;
- if( $a
- recur();
- echo $a . “, “;
- }
- function recur() {
- global $a;
- $a++;
- // how did I get here?
- echo “\n\n\n”;
- debug_print_backtrace();
- if( $a
- 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()
这个函数返回单词的metaphone值,相同读音的单词具有相同的metaphone值,也就是说这个函数可以帮你判断两个单词的读音是否相同。不过对中文就无效了。
8. natsort()
natsort()能将一个数组以自然排序法进行排列,直接看个例子吧:
-
- $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
# )
9. levenshtein()
Levenshtein()告诉你两个单词之间的“距离”。它告诉你如果想把一个单词变成另一个单词,需要插入、替换和删除多少字母。看个例子吧:
-
- $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()会让你觉得用opendir(), readdir()和closedir()来寻找文件非常蠢。
-
- foreach (glob(“*.php”) as $file) {
- echo “$file\n”;
- }
- ?>
所以要处理下
当输入<script>alert('www.jb51.net')</script>
一提交就会运行javascript
这样不好 必须处理下来防止黑客找到你攻击的入口
表单默认提交方式是get
*/
//当你输入
www.jb51.net
echo htmlspecialchars($_GET['title']);//过滤了
结果:
www.jb51.net
其他查看源码就知道已经被替换了成就会在页面原型显示
还有一点要主要 如果不处理
htmllentities()函数用户和htmlspecialchars()相反用法就不说了
当你需要那个标签留着可以用到strip_tags()函数
echo strip_tags($_GET['title'],'
/* //number_format()这个函数是格式化货币函数 不同国家的习惯不一样那么需要的货币显示就不一样例如商城中国钱是通常是这样的格式 //strrev()使字符串反倒过来 //md5就是加密 用户名密码必须要加密防止黑客 time() 返回当前的unix时间戳 is_string()判断变量是不是字符串 is_bool is_Inteter is_float strtotime -- 将任何英文文本的日期时间描述解析为 UNIX 时间戳 file_exists 检查文件或目录存不存在 fopen()打开指定的文件或URL feof()判断文件指针是否在末尾 fgets()从文件指针中读取一行 trim()去掉一行前后的空格 strlen()返回字符串的长度 get_include_path 获取当前include_path count() 返回数组长度,非数组返回1 preg_replace 执行一个正则表达式的替换 preg_match(string pattern, string subject [, array matches [, int flags]]) -- 进行正则表达式匹配 1. sys_getloadavg() sys_getloadavt()可以获得系统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。 与其让服务器因负载过高而宕掉,不如在系统负载很高时主动die掉一个脚本,sys_getloadavg()就是用来帮你实现这个功能的。 不过很遗憾,该函数在windows下无效。 Pack()能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。 cal_days_in_month()能够返回指定月份共有多少天。 WordPress开发者经常能见到这个函数,还有_e()。这两个函数功能相同,与gettext()函数结合使用,能实现网站的多语言化。具体可参见PHP手册的相关部分介绍。 在发送页面前先看看用户的浏览器都能做些什么是不是挺好?get_browser()能获得用户的浏览器类型,以及浏览器支持的功能,不过首先你需要一个php_browscap.ini文件,用来给函数做参考文件。 要注意,该函数对浏览器功能的判断是基于该类浏览器的一般特性的。例如,如果用户关闭了浏览器对JavaScript的支持,函数无法得知这一点。但是在判断浏览器类型和OS平台方面,该函数还是很准确的。 6. debug_print_backtrace() 这是一个调试用的函数,能帮助你发现代码中的逻辑错误。要理解这个函数,还是直接看个例子吧: 7. metaphone() 这个函数返回单词的metaphone值,相同读音的单词具有相同的metaphone值,也就是说这个函数可以帮你判断两个单词的读音是否相同。不过对中文就无效了。 8. natsort() natsort()能将一个数组以自然排序法进行排列,直接看个例子吧: 9. levenshtein() Levenshtein()告诉你两个单词之间的“距离”。它告诉你如果想把一个单词变成另一个单词,需要插入、替换和删除多少字母。看个例子吧: 10. glob() glob()会让你觉得用opendir(), readdir()和closedir()来寻找文件非常蠢。');
提交结果是你查看源码 就会发现
加入输入i love 'jb51';
提交结果为 i love \'jb51\'反斜杠转义了
那么我要想原文输出怎么办呢
可以用这个php函数stripslashes()
取消转义
echo stripslashes($_GET['title']);
结果是i love 'jb51';
如果含有html标签呢如这种
i love 'jb51'
我要原型输出怎么办 可以用2个函数结合起来用 我已经说过的
echo htmlspecialchars(stripslashes($_GET['title']));
结果:i love 'jb51'
*/
千分位分割用逗号 保留几位用点 人称‘小数点'
这个函数的用法很简单
number_format($money,小数点保留几位,'小数点用什么分开','千分位用什么分开')
$price='123465789.233';
echo number_format($money,2,',','.');
结果:123.465.789,23
echo number_format($money,2,'.',',');//中国式的
结果:123,465,789.23
$str='http://www.jb51.net';
echo strrev($str);
结果:moc.tenwii.www//:ptth
$a='admin';
echo $b= md5($a);
__FILE__ 返回文件的绝对路径D:\Projects\mantis\test.php
$_SERVER['HTTP_X_FORWARDED_PROTO']
$_SERVER['HTTPS']
$_SERVER['SERVER_PORT']
$_SERVER["REQUEST_URI"] URI 用来指定要访问的页面
$GLOBALS一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
explode 使用一个字符串分割另一个字符串 返回一个字符串数组
implode 使用一个字符将数组元素链接成字符串
$_SERVER['SERVER_NAME'] 当前脚本所在服务器的主机名
$_SERVER['HTTP_HOST'] 域名
$_SERVER['SERVER_ADDR'] 当前脚本所在服务器的IP地址
trim去除字符串首尾处的空白字符
basename 返回文件名部分
dirname 返回目录部分
krsort — 对数组按照键名逆向排序
set_time_limit()设置脚本最大执行时间
isset
str_replace( "\0", '', $t_self ) 将t_self中的\0替换成“”
strpos — 查找在字符串中首次出现的位置
$_SERVER['SERVER_SOFTWARE'] 服务器信息
realpath 返回规范化的绝对路径名
DIRECTORY_SEPARATOR 操作系统目录分隔符
PATH_SEPARATOR 在linux系统中是一个" : "号,Windows上是一个";"号
set_include_path 设置incldue_path
$_SERVER['LOCAL_ADDR'] IIS7上用来获取服务器IP地址
$_SERVER['REMOTE_ADDR'] 浏览器用户的IP地址
array_pad — 用值将数组填补到指定长度
memory_get_usage()返回分配给PHP的内存量
spl_autoload_register 注册__autoload()函数
ob_get_contents() Return the contents of the output buffer
strtolower() 将大写字母转换为小写字母
extension_loaded('zlib')找出扩展是否被加载
ini_get 返回php.ini中配置项的值
ini_set 设置php.ini中配置项的值 ,ini_set("memory_limit",'256M'); 只在脚本执行期间生效,脚本执行完成该值重置
PHP_EOL PHP行结束符
ceil() 进一法取整
floor() 舍去法取整
round()四舍五入法
非常有用的10个不常见PHP内置函数
2. pack()
3. cal_days_in_month()
4. _()
5. get_browser()
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]
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
# )

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Un tableau est une structure de données utilisée pour stocker des éléments homogènes en séquence. Les éléments stockés sont identifiés par des valeurs d'index ou des clés. Python n'a pas de structure de données spécifique pour représenter les tableaux. Cependant, nous pouvons utiliser la structure de données List ou le module Numpy pour gérer les tableaux. Dans l'article suivant, nous apprendrons comment inverser les éléments d'un tableau à l'aide des fonctions intégrées de Python. Inverser les éléments du tableau signifie changer l’ordre des éléments du tableau de l’avant vers l’arrière. Scénarios d'entrée-sortie Examinons maintenant quelques scénarios d'entrée-sortie pour comprendre l'inversion des éléments du tableau. Inputarray : [3,5,1,4,0,2]Outputarray : [2,0,4,1,5,3] L'ordre ou la disposition des éléments du tableau d'entrée est inversé. Utilisez le

PHP fournit une série de fonctions intégrées pour effectuer diverses tâches, notamment : les opérations sur les chaînes (strcmp, strtoupper, strtolower) le traitement des tableaux (array_push, array_pop, in_array) les opérations mathématiques (round, abs, max) le traitement des fichiers (fopen, fread , ffermer)

Aujourd'hui, je voudrais recommander une fonction intégrée très facile à utiliser en Python, qui est la méthode lambda. Ce tutoriel partagera avec vous en gros : Qu'est-ce que la fonction lambda filtre les éléments de la liste. La fonction et la méthode map() utilisent la fonction lambda. Quand est-il inapproprié d'utiliser la méthode lambda en conjonction avec la méthode apply() ? En Python, nous utilisons souvent le mot-clé lambda pour déclarer une fonction anonyme ? . La fonction dite anonyme est, en termes simples, une fonction sans nom. Le format de syntaxe spécifique est le suivant : arguments lambda : expression où elle peut être connectée.

La vie est courte, apprenez Python pour les débutants ! Je suis un frère débutant Aujourd'hui, nous allons partager 6 fonctions magiques intégrées à la fois. Dans de nombreux manuels informatiques, elles sont également généralement présentées comme des fonctions d'ordre supérieur. Dans mon travail quotidien, je les utilise souvent pour rendre le code plus rapide et plus facile à comprendre. Fonction Lambda La fonction Lambda est utilisée pour créer des fonctions anonymes, c'est-à-dire des fonctions sans nom. Ce n'est qu'une expression et le corps de la fonction est beaucoup plus simple que def. Les fonctions anonymes sont utilisées lorsque nous devons créer une fonction qui effectue une seule opération et peut être écrite sur une seule ligne. lambda [arg1 [,arg2,...argn]] : expression principale de lambda

En tant que langage de programmation populaire, l'utilisation généralisée de PHP bénéficie de sa flexibilité et de ses puissantes fonctions intégrées. Ces fonctions intégrées peuvent à la fois accélérer le processus de développement et améliorer la lisibilité et la maintenabilité du code. Que vous soyez débutant ou développeur expérimenté, vous devez connaître et maîtriser ces outils essentiels. Certaines fonctions intégrées PHP couramment utilisées incluent : Fonctions de chaîne Les chaînes sont l'un des types de données les plus courants en PHP. Les fonctions de chaîne nous permettent de traiter des chaînes, telles que la recherche, le remplacement, le fractionnement et le formatage.

Utilisation des fonctions intégrées de JavaScript pour les opérations sur les chaînes En JavaScript, de nombreuses fonctions intégrées peuvent être utilisées pour gérer les opérations sur les chaînes. Ces fonctions peuvent nous aider à modifier la casse des chaînes, à rechercher des sous-chaînes, à remplacer des caractères, etc. Cet article présentera certaines fonctions de manipulation de chaînes couramment utilisées et donnera des exemples de code correspondants. Les deux fonctions toUpperCase() et toLowerCase() sont utilisées respectivement pour convertir des chaînes en majuscules et en minuscules. Par exemple : varstr=

En tant que langage de programmation flexible et puissant, Python a conquis le cœur des programmeurs, des experts en données et des artisans logiciels du monde entier. L'adoption massive de Python découle de son riche ensemble de commandes natives qui simplifient les processus complexes, réduisent le temps de développement et améliorent la lisibilité des scripts. Dans cet article, nous examinerons en profondeur dix commandes natives Python clés que chaque programmeur doit maîtriser pour un parcours de codage fluide et efficace. Utilisation de la fonction len() La commande len() est un mécanisme simple mais indispensable pour déterminer la taille (c'est-à-dire le nombre de composants) d'un objet itérable spécifié tel qu'une liste, un tuple ou une chaîne. Exemple d'expression="Python"

Les fonctions intégrées sont des fonctions prédéfinies au cœur de Go qui facilitent l'exécution de tâches courantes telles que les conversions de types, la manipulation de chaînes et les opérations mathématiques. Plus précisément, ils incluent : Des fonctions de conversion de type qui permettent la conversion entre différents types, tels que string, int et float64. La fonction de traitement de chaîne prend en charge des opérations telles que l'obtention de la longueur, l'extraction de sous-chaînes et la conversion de casse. Fonctions mathématiques qui calculent les valeurs absolues, les valeurs maximales, les valeurs minimales et les arrondis. Ces fonctions simplifient le processus de développement en fournissant un moyen efficace et standardisé d'effectuer diverses opérations pour améliorer la qualité et l'efficacité du code.
