PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

一文汇总PHP中最全的常用函数(收藏)

藏色散人
藏色散人 转载
2023-02-27 15:55:09 5622浏览

本篇文章给大家带来了关于php的相关知识,其中主要给大家总结了php常用的函数,包含math函数、字符串函数、数组函数、多字节字符串函数、时间函数、目录函数、文件系统函数,感兴趣的朋友下面一起来看一下吧,欢迎大家收藏学习!

Math 函数

abs — 绝对值

acos — 反余弦

acosh — 反双曲余弦

asin — 反正弦

asinh — 反双曲正弦

atan2 — 两个参数的反正切

atan — 反正切

atanh — 反双曲正切

base_convert — 在任意进制之间转换数字

bindec — 二进制转换为十进制

ceil — 进一法取整

cos — 余弦

cosh — 双曲余弦

decbin — 十进制转换为二进制

dechex — 十进制转换为十六进制

decoct — 十进制转换为八进制

deg2rad — 将角度转换为弧度

exp — 计算 e 的指数

expm1 — 返回 exp(number) - 1,甚至当 number 的值接近零也能计算出准确结果

floor — 舍去法取整

fmod — 返回除法的浮点数余数

getrandmax — 显示随机数最大的可能值

hexdec — 十六进制转换为十进制

hypot — 计算一直角三角形的斜边长度

intdiv — 对除法结果取整

is_finite — 判断是否为有限值

is_infinite — 判断是否为无限值

is_nan — 判断是否为合法数值

lcg_value — 组合线性同余发生器

log10 — 以 10 为底的对数

log1p — 返回 log(1 + number),甚至当 number 的值接近零也能计算出准确结果

log — 自然对数

max — 找出最大值

min — 找出最小值

mt_getrandmax — 显示随机数的最大可能值

mt_rand — 生成更好的随机数

mt_srand — 播下一个更好的随机数发生器种子

octdec — 八进制转换为十进制

pi — 得到圆周率值

pow — 指数表达式

rad2deg — 将弧度数转换为相应的角度数

rand — 产生一个随机整数

round — 对浮点数进行四舍五入

sin — 正弦

sinh — 双曲正弦

sqrt — 平方根

srand — 播下随机数发生器种子

tan — 正切

tanh — 双曲正切

字符串函数

addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符

addslashes — 使用反斜线引用字符串

bin2hex — 函数把包含数据的二进制字符串转换为十六进制值

chop — rtrim 的别名

chr — 返回指定的字符

chunk_split — 将字符串分割成小块

convert_cyr_string — 将字符由一种 Cyrillic 字符转换成另一种

convert_uudecode — 解码一个 uuencode 编码的字符串

convert_uuencode — 使用 uuencode 编码一个字符串

count_chars — 返回字符串所用字符的信息

crc32 — 计算一个字符串的 crc32 多项式

crypt — 单向字符串散列

echo — 输出一个或多个字符串

explode — 使用一个字符串分割另一个字符串

fprintf — 将格式化后的字符串写入到流

get_html_translation_table — 返回使用 htmlspecialchars 和 htmlentities 后的转换表

hebrev — 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

hebrevc — 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew),并且转换换行符

hex2bin — 转换十六进制字符串为二进制字符串

html_entity_decode — Convert HTML entities to their corresponding characters

htmlentities — 将字符转换为 HTML 转义字符

htmlspecialchars_decode — 将特殊的 HTML 实体转换回普通字符

htmlspecialchars — 将特殊字符转换为 HTML 实体

implode — 将一个一维数组的值转化为字符串

join — 别名 implode

lcfirst — 使一个字符串的第一个字符小写

levenshtein — 计算两个字符串之间的编辑距离

localeconv — Get numeric formatting information

ltrim — 删除字符串开头的空白字符(或其他字符)

md5_file — 计算指定文件的 MD5 散列值

md5 — 计算字符串的 MD5 散列值

metaphone — Calculate the metaphone key of a string

money_format — 将数字格式化成货币字符串

nl_langinfo — Query language and locale information

nl2br — 在字符串所有新行之前插入 HTML 换行标记

number_format — 以千位分隔符方式格式化一个数字

ord — 转换字符串第一个字节为 0-255 之间的值

parse_str — 将字符串解析成多个变量

print — 输出字符串

printf — 输出格式化字符串

quoted_printable_decode — 将 quoted-printable 字符串转换为 8-bit 字符串

quoted_printable_encode — 将 8-bit 字符串转换成 quoted-printable 字符串

quotemeta — 转义元字符集

rtrim — 删除字符串末端的空白字符(或者其他字符)

setlocale — 设置地区信息

sha1_file — 计算文件的 sha1 散列值

sha1 — 计算字符串的 sha1 散列值

similar_text — 计算两个字符串的相似度

soundex — Calculate the soundex key of a string

sprintf — Return a formatted string

sscanf — 根据指定格式解析输入的字符

str_getcsv — 解析 CSV 字符串为一个数组

str_ireplace — str_replace 的忽略大小写版本

str_pad — 使用另一个字符串填充字符串为指定长度

str_repeat — 重复一个字符串

str_replace — 子字符串替换

str_rot13 — 对字符串执行 ROT13 转换

str_shuffle — 随机打乱一个字符串

str_split — 将字符串转换为数组

str_word_count — 返回字符串中单词的使用情况

strcasecmp — 二进制安全比较字符串(不区分大小写)

strchr — 别名 strstr

strcmp — 二进制安全字符串比较

strcoll — 基于区域设置的字符串比较

strcspn — 获取不匹配遮罩的起始子字符串的长度

strip_tags — 从字符串中去除 HTML 和 PHP 标记

stripcslashes — 反引用一个使用 addcslashes 转义的字符串

stripos — 查找字符串首次出现的位置(不区分大小写)

stripslashes — 反引用一个引用字符串

stristr — strstr 函数的忽略大小写版本

strlen — 获取字符串长度

strnatcasecmp — 使用“自然顺序”算法比较字符串(不区分大小写)

strnatcmp — 使用自然排序算法比较字符串

strncasecmp — 二进制安全比较字符串开头的若干个字符(不区分大小写)

strncmp — 二进制安全比较字符串开头的若干个字符

strpbrk — 在字符串中查找一组字符的任何一个字符

strpos — 查找字符串首次出现的位置

strrchr — 查找指定字符在字符串中的最后一次出现

strrev — 反转字符串

strripos — 计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)

strrpos — 计算指定字符串在目标字符串中最后一次出现的位置

strspn — 计算字符串中全部字符都存在于指定字符集合中的第一段子串的长度。

strstr — 查找字符串的首次出现

strtok — 标记分割字符串

strtolower — 将字符串转化为小写

strtoupper — 将字符串转化为大写

strtr — 转换指定字符

substr_compare — 二进制安全比较字符串(从偏移位置比较指定长度)

substr_count — 计算字串出现的次数

substr_replace — 替换字符串的子串

substr — 返回字符串的子串

trim — 去除字符串首尾处的空白字符(或者其他字符)

ucfirst — 将字符串的首字母转换为大写

ucwords — 将字符串中每个单词的首字母转换为大写

vfprintf — 将格式化字符串写入流

vprintf — 输出格式化字符串

vsprintf — 返回格式化字符串

wordwrap — 打断字符串为指定数量的字串

数组函数

array_change_key_case — 将数组中的所有键名修改为全大写或小写

array_chunk — 将一个数组分割成多个

array_column — 返回数组中指定的一列

array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值

array_count_values — 统计数组中所有的值

array_diff_assoc — 带索引检查计算数组的差集

array_diff_key — 使用键名比较计算数组的差集

array_diff_uassoc — 用用户提供的回调函数做索引检查来计算数组的差集

array_diff_ukey — 用回调函数对键名比较计算数组的差集

array_diff — 计算数组的差集

array_fill_keys — 使用指定的键和值填充数组

array_fill — 用给定的值填充数组

array_filter — 用回调函数过滤数组中的单元

array_flip — 交换数组中的键和值

array_intersect_assoc — 带索引检查计算数组的交集

array_intersect_key — 使用键名比较计算数组的交集

array_intersect_uassoc — 带索引检查计算数组的交集,用回调函数比较索引

array_intersect_ukey — 用回调函数比较键名来计算数组的交集

array_intersect — 计算数组的交集

array_key_exists — 检查数组里是否有指定的键名或索引

array_key_first — Gets the first key of an array

array_key_last — Gets the last key of an array

array_keys — 返回数组中部分的或所有的键名

array_map — 为数组的每个元素应用回调函数

array_merge_recursive — 递归地合并一个或多个数组

array_merge — 合并一个或多个数组

array_multisort — 对多个数组或多维数组进行排序

array_pad — 以指定长度将一个值填充进数组

array_pop — 弹出数组最后一个单元(出栈)

array_product — 计算数组中所有值的乘积

array_push — 将一个或多个单元压入数组的末尾(入栈)

array_rand — 从数组中随机取出一个或多个单元

array_reduce — 用回调函数迭代地将数组简化为单一的值

array_replace_recursive — 使用传递的数组递归替换第一个数组的元素

array_replace — 使用传递的数组替换第一个数组的元素

array_reverse — 返回单元顺序相反的数组

array_search — 在数组中搜索给定的值,如果成功则返回首个相应的键名

array_shift — 将数组开头的单元移出数组

array_slice — 从数组中取出一段

array_splice — 去掉数组中的某一部分并用其它值取代

array_sum — 对数组中所有值求和

array_udiff_assoc — 带索引检查计算数组的差集,用回调函数比较数据

array_udiff_uassoc — 带索引检查计算数组的差集,用回调函数比较数据和索引

array_udiff — 用回调函数比较数据来计算数组的差集

array_uintersect_assoc — 带索引检查计算数组的交集,用回调函数比较数据

array_uintersect_uassoc — 带索引检查计算数组的交集,用单独的回调函数比较数据和索引

array_uintersect — 计算数组的交集,用回调函数比较数据

array_unique — 移除数组中重复的值

array_unshift — 在数组开头插入一个或多个单元

array_values — 返回数组中所有的值

array_walk_recursive — 对数组中的每个成员递归地应用用户函数

array_walk — 使用用户自定义函数对数组中的每个元素做回调处理

array — 新建一个数组

arsort — 对数组进行逆向排序并保持索引关系

asort — 对数组进行排序并保持索引关系

compact — 建立一个数组,包括变量名和它们的值

count — 计算数组中的单元数目,或对象中的属性个数

current — 返回数组中的当前单元

each — 返回数组中当前的键/值对并将数组指针向前移动一步

end — 将数组的内部指针指向最后一个单元

extract — 从数组中将变量导入到当前的符号表

in_array — 检查数组中是否存在某个值

key_exists — 别名 array_key_exists

key — 从关联数组中取得键名

krsort — 对数组按照键名逆向排序

ksort — 对数组按照键名排序

list — 把数组中的值赋给一组变量

natcasesort — 用“自然排序”算法对数组进行不区分大小写字母的排序

natsort — 用“自然排序”算法对数组排序

next — 将数组中的内部指针向前移动一位

pos — current 的别名

prev — 将数组的内部指针倒回一位

range — 根据范围创建数组,包含指定的元素

reset — 将数组的内部指针指向第一个单元

rsort — 对数组逆向排序

shuffle — 打乱数组

sizeof — count 的别名

sort — 对数组排序

uasort — 使用用户自定义的比较函数对数组中的值进行排序并保持索引关联

uksort — 使用用户自定义的比较函数对数组中的键名进行排序

usort — 使用用户自定义的比较函数对数组中的值进行排序

多字节字符串函数

mb_check_encoding — 检查字符串在指定的编码里是否有效

mb_chr — Get a specific character

mb_convert_case — 对字符串进行大小写转换

mb_convert_encoding — 转换字符的编码

mb_convert_kana — Convert “kana” one from another (“zen-kaku”, “han-kaku” and more)

mb_convert_variables — 转换一个或多个变量的字符编码

mb_decode_mimeheader — 解码 MIME 头字段中的字符串

mb_decode_numericentity — 根据 HTML 数字字符串解码成字符

mb_detect_encoding — 检测字符的编码

mb_detect_order — 设置/获取 字符编码的检测顺序

mb_encode_mimeheader — 为 MIME 头编码字符串

mb_encode_numericentity — Encode character to HTML numeric string reference

mb_encoding_aliases — Get aliases of a known encoding type

mb_ereg_match — Regular expression match for multibyte string

mb_ereg_replace_callback — Perform a regular expression search and replace with multibyte support using a callback

mb_ereg_replace — Replace regular expression with multibyte support

mb_ereg_search_getpos — Returns start point for next regular expression match

mb_ereg_search_getregs — Retrieve the result from the last multibyte regular expression match

mb_ereg_search_init — Setup string and regular expression for a multibyte regular expression match

mb_ereg_search_pos — Returns position and length of a matched part of the multibyte regular expression for a predefined multibyte string

mb_ereg_search_regs — Returns the matched part of a multibyte regular expression

mb_ereg_search_setpos — Set start point of next regular expression match

mb_ereg_search — Multibyte regular expression match for predefined multibyte string

mb_ereg — Regular expression match with multibyte support

mb_eregi_replace — Replace regular expression with multibyte support ignoring case

mb_eregi — Regular expression match ignoring case with multibyte support

mb_get_info — 获取 mbstring 的内部设置

mb_http_input — 检测 HTTP 输入字符编码

mb_http_output — 设置/获取 HTTP 输出字符编码

mb_internal_encoding — 设置/获取内部字符编码

mb_language — 设置/获取当前的语言

mb_list_encodings — 返回所有支持编码的数组

mb_ord — Get code point of character

mb_output_handler — 在输出缓冲中转换字符编码的回调函数

mb_parse_str — 解析 GET/POST/COOKIE 数据并设置全局变量

mb_preferred_mime_name — 获取 MIME 字符串

mb_regex_encoding — Set/Get character encoding for multibyte regex

mb_regex_set_options — Set/Get the default options for mbregex functions

mb_scrub — Description

mb_send_mail — 发送编码过的邮件

mb_split — 使用正则表达式分割多字节字符串

mb_strcut — 获取字符的一部分

mb_strimwidth — 获取按指定宽度截断的字符串

mb_stripos — 大小写不敏感地查找字符串在另一个字符串中首次出现的位置

mb_stristr — 大小写不敏感地查找字符串在另一个字符串里的首次出现

mb_strlen — 获取字符串的长度

mb_strpos — 查找字符串在另一个字符串中首次出现的位置

mb_strrchr — 查找指定字符在另一个字符串中最后一次的出现

mb_strrichr — 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现

mb_strripos — 大小写不敏感地在字符串中查找一个字符串最后出现的位置

mb_strrpos — 查找字符串在一个字符串中最后出现的位置

mb_strstr — 查找字符串在另一个字符串里的首次出现

mb_strtolower — 使字符串小写

mb_strtoupper — 使字符串大写

mb_strwidth — 返回字符串的宽度

mb_substitute_character — 设置/获取替代字符

mb_substr_count — 统计字符串出现的次数

mb_substr — 获取部分字符串

时间函数

checkdate — 验证一个格里高里日期

date_add — 别名 DateTime::add

date_create_from_format — 别名 DateTime::createFromFormat

date_create_immutable_from_format — 别名 DateTimeImmutable::createFromFormat

date_create_immutable — 别名 DateTimeImmutable::__construct

date_create — 别名 DateTime::__construct

date_date_set — 别名 DateTime::setDate

date_default_timezone_get — 取得一个脚本中所有日期时间函数所使用的默认时区

date_default_timezone_set — 设定用于一个脚本中所有日期时间函数的默认时区

date_diff — 别名 DateTime::diff

date_format — 别名 DateTime::format

date_get_last_errors — 别名 DateTime::getLastErrors

date_interval_create_from_date_string — 别名 DateInterval::createFromDateString

date_interval_format — 别名 DateInterval::format

date_isodate_set — 别名 DateTime::setISODate

date_modify — 别名 DateTime::modify

date_offset_get — 别名 DateTime::getOffset

date_parse_from_format — Get info about given date formatted according to the specified format

date_parse — Returns associative array with detailed info about given date

date_sub — 别名 DateTime::sub

date_sun_info — Returns an array with information about sunset/sunrise and twilight begin/end

date_sunrise — 返回给定的日期与地点的日出时间

date_sunset — 返回给定的日期与地点的日落时间

date_time_set — 别名 DateTime::setTime

date_timestamp_get — 别名 DateTime::getTimestamp

date_timestamp_set — 别名 DateTime::setTimestamp

date_timezone_get — 别名 DateTime::getTimezone

date_timezone_set — 别名 DateTime::setTimezone

date — 格式化一个本地时间/日期

getdate — 取得日期/时间信息

gettimeofday — 取得当前时间

gmdate — 格式化一个 GMT/UTC 日期/时间

gmmktime — 取得 GMT 日期的 UNIX 时间戳

gmstrftime — 根据区域设置格式化 GMT/UTC 时间/日期

idate — 将本地时间日期格式化为整数

localtime — 取得本地时间

microtime — 返回当前 Unix 时间戳和微秒数

mktime — 取得一个日期的 Unix 时间戳

strftime — 根据区域设置格式化本地时间/日期

strptime — 解析由 strftime 生成的日期/时间

strtotime — 将任何字符串的日期时间描述解析为 Unix 时间戳

time — 返回当前的 Unix 时间戳

timezone_abbreviations_list — 别名 DateTimeZone::listAbbreviations

timezone_identifiers_list — 别名 DateTimeZone::listIdentifiers

timezone_location_get — 别名 DateTimeZone::getLocation

timezone_name_from_abbr — Returns the timezone name from abbreviation

timezone_name_get — 别名 DateTimeZone::getName

timezone_offset_get — 别名 DateTimeZone::getOffset

timezone_open — 别名 DateTimeZone::__construct

timezone_transitions_get — 别名 DateTimeZone::getTransitions

timezone_version_get — Gets the version of the timezonedb

目录函数

chdir — 改变目录

chroot — 改变根目录

closedir — 关闭目录句柄

dir — 返回一个 Directory 类实例

getcwd — 取得当前工作目录

opendir — 打开目录句柄

readdir — 从目录句柄中读取条目

rewinddir — 倒回目录句柄

scandir — 列出指定路径中的文件和目录

文件系统函数

basename — 返回路径中的文件名部分

chgrp — 改变文件所属的组

chmod — 改变文件模式

chown — 改变文件的所有者

clearstatcache — 清除文件状态缓存

copy — 拷贝文件

delete — 参见 unlink 或 unset

dirname — 返回路径中的目录部分

disk_free_space — 返回目录中的可用空间

disk_total_space — 返回一个目录的磁盘总大小

diskfreespace — disk_free_space 的别名

fclose — 关闭一个已打开的文件指针

feof — 测试文件指针是否到了文件结束的位置

fflush — 将缓冲内容输出到文件

fgetc — 从文件指针中读取字符

fgetcsv — 从文件指针中读入一行并解析 CSV 字段

fgets — 从文件指针中读取一行

fgetss — 从文件指针中读取一行并过滤掉 HTML 标记

file_exists — 检查文件或目录是否存在

file_get_contents — 将整个文件读入一个字符串

file_put_contents — 将一个字符串写入文件

file — 把整个文件读入一个数组中

fileatime — 取得文件的上次访问时间

filectime — 取得文件的 inode 修改时间

filegroup — 取得文件的组

fileinode — 取得文件的 inode

filemtime — 取得文件修改时间

fileowner — 取得文件的所有者

fileperms — 取得文件的权限

filesize — 取得文件大小

filetype — 取得文件类型

flock — 轻便的咨询文件锁定

fnmatch — 用模式匹配文件名

fopen — 打开文件或者 URL

fpassthru — 输出文件指针处的所有剩余数据

fputcsv — 将行格式化为 CSV 并写入文件指针

fputs — fwrite 的别名

fread — 读取文件(可安全用于二进制文件)

fscanf — 从文件中格式化输入

fseek — 在文件指针中定位

fstat — 通过已打开的文件指针取得文件信息

ftell — 返回文件指针读/写的位置

ftruncate — 将文件截断到给定的长度

fwrite — 写入文件(可安全用于二进制文件)

glob — 寻找与模式匹配的文件路径

is_dir — 判断给定文件名是否是一个目录

is_executable — 判断给定文件名是否可执行

is_file — 判断给定文件名是否为一个正常的文件

is_link — 判断给定文件名是否为一个符号连接

is_readable — 判断给定文件名是否可读

is_uploaded_file — 判断文件是否是通过 HTTP POST 上传的

is_writable — 判断给定的文件名是否可写

is_writeable — is_writable 的别名

lchgrp — 修改符号链接的所有组

lchown — 修改符号链接的所有者

link — 建立一个硬连接

linkinfo — 获取一个连接的信息

lstat — 给出一个文件或符号连接的信息

mkdir — 新建目录

move_uploaded_file — 将上传的文件移动到新位置

parse_ini_file — 解析一个配置文件

parse_ini_string — 解析配置字符串

pathinfo — 返回文件路径的信息

pclose — 关闭进程文件指针

popen — 打开进程文件指针

readfile — 输出文件

readlink — 返回符号连接指向的目标

realpath_cache_get — 获取真实目录缓存的详情

realpath_cache_size — 获取真实路径缓冲区的大小

realpath — 返回规范化的绝对路径名

rename — 重命名一个文件或目录

rewind — 倒回文件指针的位置

rmdir — 删除目录

set_file_buffer — stream_set_write_buffer 的别名

stat — 给出文件的信息

symlink — 建立符号连接

tempnam — 建立一个具有唯一文件名的文件

tmpfile — 建立一个临时文件

touch — 设定文件的访问和修改时间

umask — 改变当前的 umask

unlink — 删除文件

推荐学习:《PHP视频教程

声明:本文转载于:learnku,如有侵犯,请联系admin@php.cn删除