strlentools.php-function-query.categories.string
获取字符串的字节长度,注意中文 UTF-8 下一个汉字占 3 字节。
tools.php-function-query.labels.syntax
strlen(string $string): inttools.php-function-query.labels.example
strlen('hello') // 5中文计数请使用 mb_strlen。
mb_strlentools.php-function-query.categories.string
按多字节字符获取字符串长度,支持 UTF-8 等编码。
tools.php-function-query.labels.syntax
mb_strlen(string $string, ?string $encoding = null): inttools.php-function-query.labels.example
mb_strlen('你好世界', 'UTF-8') // 4strpostools.php-function-query.categories.string
查找子串在字符串中第一次出现的位置,未找到返回 false。
tools.php-function-query.labels.syntax
strpos(string $haystack, string $needle, int $offset = 0): int|falsetools.php-function-query.labels.example
strpos('hello world', 'world') // 6判断结果时务必使用 !== false 严格比较。
stripostools.php-function-query.categories.string
不区分大小写的 strpos 变体。
tools.php-function-query.labels.syntax
stripos(string $haystack, string $needle, int $offset = 0): int|falsetools.php-function-query.labels.example
stripos('Hello', 'e') // 1str_replacetools.php-function-query.categories.string
在字符串中查找并替换内容,支持数组批量替换。
tools.php-function-query.labels.syntax
str_replace(array|string $search, array|string $replace, string|array $subject, int &$count = null): string|arraytools.php-function-query.labels.example
str_replace('foo', 'bar', 'foobar') // 'barbar'preg_replacetools.php-function-query.categories.string
按正则模式查找并替换字符串。
tools.php-function-query.labels.syntax
preg_replace(string|array $pattern, string|array $replacement, string|array $subject): string|array|nulltools.php-function-query.labels.example
preg_replace('/\\d+/', '#', 'abc123') // 'abc#'substrtools.php-function-query.categories.string
截取字符串的一部分,按字节计算。
tools.php-function-query.labels.syntax
substr(string $string, int $offset, ?int $length = null): stringtools.php-function-query.labels.example
substr('hello', 1, 3) // 'ell'处理中文用 mb_substr 更安全。
mb_substrtools.php-function-query.categories.string
按多字节字符截取字符串。
tools.php-function-query.labels.syntax
mb_substr(string $string, int $start, ?int $length = null, ?string $encoding = null): stringtools.php-function-query.labels.example
mb_substr('你好世界', 0, 2) // '你好'trimtools.php-function-query.categories.string
去除字符串首尾的空白字符或指定字符。
tools.php-function-query.labels.syntax
trim(string $string, string $characters = " \t\n\r\0\x0B"): stringtools.php-function-query.labels.example
trim(' hi ') // 'hi'ltrimtools.php-function-query.categories.string
去除字符串左侧空白或指定字符。
tools.php-function-query.labels.syntax
ltrim(string $string, string $characters = " \t\n\r\0\x0B"): stringtools.php-function-query.labels.example
ltrim(' hi') // 'hi'rtrimtools.php-function-query.categories.string
去除字符串右侧空白或指定字符。
tools.php-function-query.labels.syntax
rtrim(string $string, string $characters = " \t\n\r\0\x0B"): stringtools.php-function-query.labels.example
rtrim('hi ') // 'hi'strtolowertools.php-function-query.categories.string
将字符串中的 ASCII 字母转换为小写。
tools.php-function-query.labels.syntax
strtolower(string $string): stringtools.php-function-query.labels.example
strtolower('Hello') // 'hello'处理 Unicode 用 mb_strtolower。
strtouppertools.php-function-query.categories.string
将字符串中的 ASCII 字母转换为大写。
tools.php-function-query.labels.syntax
strtoupper(string $string): stringtools.php-function-query.labels.example
strtoupper('Hello') // 'HELLO'ucfirsttools.php-function-query.categories.string
将字符串首字母转大写。
tools.php-function-query.labels.syntax
ucfirst(string $string): stringtools.php-function-query.labels.example
ucfirst('hello world') // 'Hello world'ucwordstools.php-function-query.categories.string
将每个单词的首字母转大写。
tools.php-function-query.labels.syntax
ucwords(string $string, string $separators = " \t\r\n\f\v"): stringtools.php-function-query.labels.example
ucwords('hello world') // 'Hello World'explodetools.php-function-query.categories.string
按指定分隔符将字符串拆分为数组。
tools.php-function-query.labels.syntax
explode(string $separator, string $string, int $limit = PHP_INT_MAX): arraytools.php-function-query.labels.example
explode(',', 'a,b,c') // ['a','b','c']implodetools.php-function-query.categories.string
用分隔符拼接数组为字符串,等同于 join。
tools.php-function-query.labels.syntax
implode(string $separator, array $array): stringtools.php-function-query.labels.example
implode('-', ['a','b','c']) // 'a-b-c'sprintftools.php-function-query.categories.string
按格式化字符串返回新的字符串,不直接输出。
tools.php-function-query.labels.syntax
sprintf(string $format, mixed ...$values): stringtools.php-function-query.labels.example
sprintf('%05d', 42) // '00042'number_formattools.php-function-query.categories.string
按千分位与指定小数位格式化数字。
tools.php-function-query.labels.syntax
number_format(float $num, int $decimals = 0, string $decimal_separator = '.', string $thousands_separator = ','): stringtools.php-function-query.labels.example
number_format(1234567.891, 2) // '1,234,567.89'str_padtools.php-function-query.categories.string
将字符串填充到指定长度。
tools.php-function-query.labels.syntax
str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT): stringtools.php-function-query.labels.example
str_pad('5', 3, '0', STR_PAD_LEFT) // '005'str_repeattools.php-function-query.categories.string
将字符串重复指定次数后返回。
tools.php-function-query.labels.syntax
str_repeat(string $string, int $times): stringtools.php-function-query.labels.example
str_repeat('ab', 3) // 'ababab'str_splittools.php-function-query.categories.string
将字符串按固定长度分割为数组。
tools.php-function-query.labels.syntax
str_split(string $string, int $length = 1): arraytools.php-function-query.labels.example
str_split('hello', 2) // ['he','ll','o']htmlspecialcharstools.php-function-query.categories.string
把预定义的字符转换为 HTML 实体,防止 XSS。
tools.php-function-query.labels.syntax
htmlspecialchars(string $string, int $flags = ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401, ?string $encoding = null, bool $double_encode = true): stringtools.php-function-query.labels.example
htmlspecialchars('<a>') // '<a>'nl2brtools.php-function-query.categories.string
在字符串的每个换行符前插入 <br> 标签。
tools.php-function-query.labels.syntax
nl2br(string $string, bool $use_xhtml = true): stringtools.php-function-query.labels.example
nl2br("a\nb") // 'a<br />\nb'counttools.php-function-query.categories.array
统计数组元素的个数。
tools.php-function-query.labels.syntax
count(Countable|array $value, int $mode = COUNT_NORMAL): inttools.php-function-query.labels.example
count([1,2,3]) // 3对实现 Countable 的对象也适用。
array_keystools.php-function-query.categories.array
返回数组的所有键名,可指定值进行过滤。
tools.php-function-query.labels.syntax
array_keys(array $array, mixed $filter_value = null, bool $strict = false): arraytools.php-function-query.labels.example
array_keys(['a'=>1,'b'=>2]) // ['a','b']array_valuestools.php-function-query.categories.array
返回数组中所有值组成的索引数组。
tools.php-function-query.labels.syntax
array_values(array $array): arraytools.php-function-query.labels.example
array_values(['a'=>1,'b'=>2]) // [1,2]array_mergetools.php-function-query.categories.array
合并一个或多个数组,相同字符串键后者覆盖前者。
tools.php-function-query.labels.syntax
array_merge(array ...$arrays): arraytools.php-function-query.labels.example
array_merge(['a'=>1],['a'=>2,'b'=>3]) // ['a'=>2,'b'=>3]数字键会重新索引;要保留请用 + 运算符。
array_combinetools.php-function-query.categories.array
用一个数组的值作为键,另一个数组的值作为值组成新数组。
tools.php-function-query.labels.syntax
array_combine(array $keys, array $values): arraytools.php-function-query.labels.example
array_combine(['a','b'],[1,2]) // ['a'=>1,'b'=>2]array_maptools.php-function-query.categories.array
对数组每个元素应用回调函数并返回新数组。
tools.php-function-query.labels.syntax
array_map(?callable $callback, array $array, array ...$arrays): arraytools.php-function-query.labels.example
array_map(fn($n)=>$n*2,[1,2,3]) // [2,4,6]array_filtertools.php-function-query.categories.array
用回调函数过滤数组元素,保留返回 true 的项。
tools.php-function-query.labels.syntax
array_filter(array $array, ?callable $callback = null, int $mode = 0): arraytools.php-function-query.labels.example
array_filter([0,1,2,'',3]) // [1=>1,2=>2,4=>3]array_reducetools.php-function-query.categories.array
用回调函数迭代地将数组归约为单一值。
tools.php-function-query.labels.syntax
array_reduce(array $array, callable $callback, mixed $initial = null): mixedtools.php-function-query.labels.example
array_reduce([1,2,3], fn($c,$i)=>$c+$i, 0) // 6array_searchtools.php-function-query.categories.array
在数组中搜索给定值,返回第一个匹配的键,未找到返回 false。
tools.php-function-query.labels.syntax
array_search(mixed $needle, array $haystack, bool $strict = false): int|string|falsetools.php-function-query.labels.example
array_search('b', ['a','b','c']) // 1in_arraytools.php-function-query.categories.array
检查值是否存在于数组中。
tools.php-function-query.labels.syntax
in_array(mixed $needle, array $haystack, bool $strict = false): booltools.php-function-query.labels.example
in_array(2, [1,2,3]) // true建议设置 strict=true 避免松散比较导致误判。
array_key_existstools.php-function-query.categories.array
检查数组中是否存在指定的键名。
tools.php-function-query.labels.syntax
array_key_exists(string|int $key, array $array): booltools.php-function-query.labels.example
array_key_exists('a', ['a'=>null]) // true与 isset 不同,键存在但值为 null 也返回 true。
array_uniquetools.php-function-query.categories.array
去除数组中重复的值。
tools.php-function-query.labels.syntax
array_unique(array $array, int $flags = SORT_STRING): arraytools.php-function-query.labels.example
array_unique([1,2,2,3]) // [0=>1,1=>2,3=>3]array_slicetools.php-function-query.categories.array
从数组中取出一段,类似 JavaScript 的 slice。
tools.php-function-query.labels.syntax
array_slice(array $array, int $offset, ?int $length = null, bool $preserve_keys = false): arraytools.php-function-query.labels.example
array_slice([1,2,3,4,5], 1, 2) // [2,3]array_splicetools.php-function-query.categories.array
移除数组的一部分并用其他元素替换。
tools.php-function-query.labels.syntax
array_splice(array &$array, int $offset, ?int $length = null, mixed $replacement = []): arraytools.php-function-query.labels.example
$a=[1,2,3]; array_splice($a, 1, 1, ['x','y']); // $a=[1,'x','y',3]array_reversetools.php-function-query.categories.array
返回元素顺序相反的数组。
tools.php-function-query.labels.syntax
array_reverse(array $array, bool $preserve_keys = false): arraytools.php-function-query.labels.example
array_reverse([1,2,3]) // [3,2,1]array_fliptools.php-function-query.categories.array
交换数组中的键与值。
tools.php-function-query.labels.syntax
array_flip(array $array): arraytools.php-function-query.labels.example
array_flip(['a'=>1,'b'=>2]) // [1=>'a',2=>'b']array_difftools.php-function-query.categories.array
计算数组之间的差集(值比较)。
tools.php-function-query.labels.syntax
array_diff(array $array, array ...$arrays): arraytools.php-function-query.labels.example
array_diff([1,2,3],[2,4]) // [0=>1,2=>3]array_intersecttools.php-function-query.categories.array
计算数组之间的交集(值比较)。
tools.php-function-query.labels.syntax
array_intersect(array $array, array ...$arrays): arraytools.php-function-query.labels.example
array_intersect([1,2,3],[2,3,4]) // [1=>2,2=>3]array_pushtools.php-function-query.categories.array
向数组末尾插入一个或多个元素。
tools.php-function-query.labels.syntax
array_push(array &$array, mixed ...$values): inttools.php-function-query.labels.example
$a=[1]; array_push($a, 2, 3); // $a=[1,2,3]array_poptools.php-function-query.categories.array
弹出数组末尾的元素。
tools.php-function-query.labels.syntax
array_pop(array &$array): mixedtools.php-function-query.labels.example
$a=[1,2,3]; array_pop($a); // 返回 3, $a=[1,2]array_shifttools.php-function-query.categories.array
移除数组开头的元素并返回。
tools.php-function-query.labels.syntax
array_shift(array &$array): mixedtools.php-function-query.labels.example
$a=[1,2,3]; array_shift($a); // 返回 1, $a=[2,3]array_unshifttools.php-function-query.categories.array
在数组开头插入一个或多个元素。
tools.php-function-query.labels.syntax
array_unshift(array &$array, mixed ...$values): inttools.php-function-query.labels.example
$a=[2,3]; array_unshift($a, 1); // $a=[1,2,3]sorttools.php-function-query.categories.array
对数组按值升序排序,重置键。
tools.php-function-query.labels.syntax
sort(array &$array, int $flags = SORT_REGULAR): booltools.php-function-query.labels.example
$a=[3,1,2]; sort($a); // $a=[1,2,3]rsorttools.php-function-query.categories.array
对数组按值降序排序,重置键。
tools.php-function-query.labels.syntax
rsort(array &$array, int $flags = SORT_REGULAR): booltools.php-function-query.labels.example
$a=[1,3,2]; rsort($a); // $a=[3,2,1]usorttools.php-function-query.categories.array
使用用户自定义比较函数对数组进行排序。
tools.php-function-query.labels.syntax
usort(array &$array, callable $callback): booltools.php-function-query.labels.example
usort($a, fn($x,$y)=>$x<=>$y);ksorttools.php-function-query.categories.array
按键名升序对数组进行排序。
tools.php-function-query.labels.syntax
ksort(array &$array, int $flags = SORT_REGULAR): booltools.php-function-query.labels.example
ksort($arr);array_columntools.php-function-query.categories.array
从二维数组中获取一列的值。
tools.php-function-query.labels.syntax
array_column(array $array, int|string|null $column_key, int|string|null $index_key = null): arraytools.php-function-query.labels.example
array_column($rows, 'name', 'id')abstools.php-function-query.categories.math
返回数字的绝对值。
tools.php-function-query.labels.syntax
abs(int|float $num): int|floattools.php-function-query.labels.example
abs(-5) // 5roundtools.php-function-query.categories.math
对浮点数进行四舍五入。
tools.php-function-query.labels.syntax
round(int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): floattools.php-function-query.labels.example
round(1.555, 2) // 1.56ceiltools.php-function-query.categories.math
对浮点数向上取整。
tools.php-function-query.labels.syntax
ceil(int|float $num): floattools.php-function-query.labels.example
ceil(1.2) // 2floortools.php-function-query.categories.math
对浮点数向下取整。
tools.php-function-query.labels.syntax
floor(int|float $num): floattools.php-function-query.labels.example
floor(1.8) // 1maxtools.php-function-query.categories.math
返回参数中的最大值,支持数组与多个值。
tools.php-function-query.labels.syntax
max(mixed $value, mixed ...$values): mixedtools.php-function-query.labels.example
max(1, 3, 2) // 3mintools.php-function-query.categories.math
返回参数中的最小值。
tools.php-function-query.labels.syntax
min(mixed $value, mixed ...$values): mixedtools.php-function-query.labels.example
min([4,2,5]) // 2powtools.php-function-query.categories.math
返回 base 的 exp 次方。
tools.php-function-query.labels.syntax
pow(mixed $num, mixed $exponent): int|floattools.php-function-query.labels.example
pow(2, 10) // 1024sqrttools.php-function-query.categories.math
返回数字的平方根。
tools.php-function-query.labels.syntax
sqrt(float $num): floattools.php-function-query.labels.example
sqrt(16) // 4randtools.php-function-query.categories.math
生成一个伪随机整数。
tools.php-function-query.labels.syntax
rand(int $min, int $max): inttools.php-function-query.labels.example
rand(1, 100)对安全敏感的场景请使用 random_int。
mt_randtools.php-function-query.categories.math
更快、质量更好的伪随机整数生成器。
tools.php-function-query.labels.syntax
mt_rand(int $min, int $max): inttools.php-function-query.labels.example
mt_rand(0, 9999)random_inttools.php-function-query.categories.math
生成密码学安全的伪随机整数。
tools.php-function-query.labels.syntax
random_int(int $min, int $max): inttools.php-function-query.labels.example
random_int(100000, 999999) // 用于验证码intvaltools.php-function-query.categories.math
通过字符串或浮点获取整数值。
tools.php-function-query.labels.syntax
intval(mixed $value, int $base = 10): inttools.php-function-query.labels.example
intval('42abc') // 42floatvaltools.php-function-query.categories.math
通过字符串获取浮点数值。
tools.php-function-query.labels.syntax
floatval(mixed $value): floattools.php-function-query.labels.example
floatval('3.14abc') // 3.14timetools.php-function-query.categories.date
返回当前 Unix 时间戳(秒)。
tools.php-function-query.labels.syntax
time(): inttools.php-function-query.labels.example
time() // 1700000000microtimetools.php-function-query.categories.date
返回当前 Unix 时间戳的毫秒部分与秒。
tools.php-function-query.labels.syntax
microtime(bool $as_float = false): string|floattools.php-function-query.labels.example
microtime(true) // 1700000000.1234as_float=true 直接返回浮点便于差值计算。
datetools.php-function-query.categories.date
按格式化字符串返回本地日期与时间。
tools.php-function-query.labels.syntax
date(string $format, ?int $timestamp = null): stringtools.php-function-query.labels.example
date('Y-m-d H:i:s') // '2024-01-01 12:00:00'mktimetools.php-function-query.categories.date
由具体日期时间分量生成 Unix 时间戳。
tools.php-function-query.labels.syntax
mktime(int $hour = ..., int $minute = ..., int $second = ..., int $month = ..., int $day = ..., int $year = ...): int|falsetools.php-function-query.labels.example
mktime(0, 0, 0, 1, 1, 2024)strtotimetools.php-function-query.categories.date
将任意英文日期描述解析为时间戳。
tools.php-function-query.labels.syntax
strtotime(string $datetime, ?int $baseTimestamp = null): int|falsetools.php-function-query.labels.example
strtotime('next monday')date_formattools.php-function-query.categories.date
对 DateTime 对象按格式化字符串生成字符串。
tools.php-function-query.labels.syntax
date_format(DateTimeInterface $object, string $format): stringtools.php-function-query.labels.example
date_format(new DateTime, 'Y-m-d')date_difftools.php-function-query.categories.date
返回两个 DateTime 之间的差值 DateInterval。
tools.php-function-query.labels.syntax
date_diff(DateTimeInterface $baseObject, DateTimeInterface $targetObject, bool $absolute = false): DateIntervaltools.php-function-query.labels.example
date_diff($a, $b)->dayscheckdatetools.php-function-query.categories.date
校验给定的年月日是否为有效公历日期。
tools.php-function-query.labels.syntax
checkdate(int $month, int $day, int $year): booltools.php-function-query.labels.example
checkdate(2, 29, 2024) // truefile_get_contentstools.php-function-query.categories.file
将整个文件读入字符串,也可读取 URL。
tools.php-function-query.labels.syntax
file_get_contents(string $filename, bool $use_include_path = false, $context = null, int $offset = 0, ?int $length = null): string|falsetools.php-function-query.labels.example
file_get_contents('config.json')file_put_contentstools.php-function-query.categories.file
将字符串写入文件,文件不存在时自动创建。
tools.php-function-query.labels.syntax
file_put_contents(string $filename, mixed $data, int $flags = 0, $context = null): int|falsetools.php-function-query.labels.example
file_put_contents('log.txt', $msg, FILE_APPEND)fopentools.php-function-query.categories.file
打开文件或 URL 资源,返回文件指针。
tools.php-function-query.labels.syntax
fopen(string $filename, string $mode, bool $use_include_path = false, $context = null): resource|falsetools.php-function-query.labels.example
$fp = fopen('data.csv', 'r')fclosetools.php-function-query.categories.file
关闭一个已打开的文件指针。
tools.php-function-query.labels.syntax
fclose(resource $stream): booltools.php-function-query.labels.example
fclose($fp)fwritetools.php-function-query.categories.file
向打开的文件写入数据。
tools.php-function-query.labels.syntax
fwrite(resource $stream, string $data, ?int $length = null): int|falsetools.php-function-query.labels.example
fwrite($fp, 'hello')freadtools.php-function-query.categories.file
从文件指针读取指定长度的内容。
tools.php-function-query.labels.syntax
fread(resource $stream, int $length): string|falsetools.php-function-query.labels.example
fread($fp, 1024)fgetstools.php-function-query.categories.file
从文件指针读取一行。
tools.php-function-query.labels.syntax
fgets(resource $stream, ?int $length = null): string|falsetools.php-function-query.labels.example
while ($line = fgets($fp)) { ... }file_existstools.php-function-query.categories.file
判断文件或目录是否存在。
tools.php-function-query.labels.syntax
file_exists(string $filename): booltools.php-function-query.labels.example
file_exists('uploads/avatar.png')is_filetools.php-function-query.categories.file
判断路径是否为常规文件。
tools.php-function-query.labels.syntax
is_file(string $filename): booltools.php-function-query.labels.example
is_file('a.txt')is_dirtools.php-function-query.categories.file
判断路径是否为目录。
tools.php-function-query.labels.syntax
is_dir(string $filename): booltools.php-function-query.labels.example
is_dir('/var/log')mkdirtools.php-function-query.categories.file
创建目录,可递归创建多级路径。
tools.php-function-query.labels.syntax
mkdir(string $directory, int $permissions = 0777, bool $recursive = false, $context = null): booltools.php-function-query.labels.example
mkdir('a/b/c', 0755, true)unlinktools.php-function-query.categories.file
删除文件。
tools.php-function-query.labels.syntax
unlink(string $filename, $context = null): booltools.php-function-query.labels.example
unlink('temp.log')renametools.php-function-query.categories.file
重命名或移动文件、目录。
tools.php-function-query.labels.syntax
rename(string $from, string $to, $context = null): booltools.php-function-query.labels.example
rename('old.txt', 'new.txt')copytools.php-function-query.categories.file
拷贝文件到目标位置。
tools.php-function-query.labels.syntax
copy(string $from, string $to, $context = null): booltools.php-function-query.labels.example
copy('a.png', 'backup/a.png')filesizetools.php-function-query.categories.file
返回文件大小(字节)。
tools.php-function-query.labels.syntax
filesize(string $filename): int|falsetools.php-function-query.labels.example
filesize('image.jpg')scandirtools.php-function-query.categories.file
列出目录中的文件和子目录。
tools.php-function-query.labels.syntax
scandir(string $directory, int $sorting_order = SCANDIR_SORT_ASCENDING, $context = null): array|falsetools.php-function-query.labels.example
scandir('./public')globtools.php-function-query.categories.file
按通配符匹配寻找文件路径。
tools.php-function-query.labels.syntax
glob(string $pattern, int $flags = 0): array|falsetools.php-function-query.labels.example
glob('logs/*.log')pathinfotools.php-function-query.categories.file
返回路径的目录、文件名、扩展名等信息。
tools.php-function-query.labels.syntax
pathinfo(string $path, int $flags = PATHINFO_ALL): array|stringtools.php-function-query.labels.example
pathinfo('/a/b.txt') // ['dirname'=>'/a',...]preg_matchtools.php-function-query.categories.regex
执行一次正则匹配,匹配成功返回 1。
tools.php-function-query.labels.syntax
preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|falsetools.php-function-query.labels.example
preg_match('/^\\d+$/', '123') // 1preg_match_alltools.php-function-query.categories.regex
执行全局正则匹配,匹配多个结果。
tools.php-function-query.labels.syntax
preg_match_all(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|falsetools.php-function-query.labels.example
preg_match_all('/\\d+/', 'a1b2c3', $m); // $m[0]=['1','2','3']preg_splittools.php-function-query.categories.regex
按正则表达式分割字符串。
tools.php-function-query.labels.syntax
preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0): array|falsetools.php-function-query.labels.example
preg_split('/\\s+/', 'a b c') // ['a','b','c']preg_quotetools.php-function-query.categories.regex
对字符串中的正则特殊字符进行转义。
tools.php-function-query.labels.syntax
preg_quote(string $str, ?string $delimiter = null): stringtools.php-function-query.labels.example
preg_quote('1+1=2') // '1\\+1=2'issettools.php-function-query.categories.variable
检测变量是否声明且不为 null。
tools.php-function-query.labels.syntax
isset(mixed $var, mixed ...$vars): booltools.php-function-query.labels.example
isset($_GET['id'])emptytools.php-function-query.categories.variable
检测变量是否为空(0/''/null/false/空数组)。
tools.php-function-query.labels.syntax
empty(mixed $var): booltools.php-function-query.labels.example
empty($name)字符串 '0' 也被视为 empty。
unsettools.php-function-query.categories.variable
销毁变量。
tools.php-function-query.labels.syntax
unset(mixed $var, mixed ...$vars): voidtools.php-function-query.labels.example
unset($tmp)gettypetools.php-function-query.categories.variable
获取变量类型字符串。
tools.php-function-query.labels.syntax
gettype(mixed $value): stringtools.php-function-query.labels.example
gettype([1,2]) // 'array'is_arraytools.php-function-query.categories.variable
判断变量是否为数组。
tools.php-function-query.labels.syntax
is_array(mixed $value): booltools.php-function-query.labels.example
is_array($x)is_stringtools.php-function-query.categories.variable
判断变量是否为字符串。
tools.php-function-query.labels.syntax
is_string(mixed $value): booltools.php-function-query.labels.example
is_string($x)is_numerictools.php-function-query.categories.variable
判断变量是否为数字或数字字符串。
tools.php-function-query.labels.syntax
is_numeric(mixed $value): booltools.php-function-query.labels.example
is_numeric('3.14') // trueis_nulltools.php-function-query.categories.variable
判断变量是否为 null。
tools.php-function-query.labels.syntax
is_null(mixed $value): booltools.php-function-query.labels.example
is_null($x)var_dumptools.php-function-query.categories.variable
打印变量的详细信息,包括类型与值,常用于调试。
tools.php-function-query.labels.syntax
var_dump(mixed ...$values): voidtools.php-function-query.labels.example
var_dump($obj)print_rtools.php-function-query.categories.variable
以易读形式打印变量信息,可返回字符串。
tools.php-function-query.labels.syntax
print_r(mixed $value, bool $return = false): string|truetools.php-function-query.labels.example
print_r($arr, true)json_encodetools.php-function-query.categories.json
将 PHP 变量编码为 JSON 字符串。
tools.php-function-query.labels.syntax
json_encode(mixed $value, int $flags = 0, int $depth = 512): string|falsetools.php-function-query.labels.example
json_encode(['a'=>1], JSON_UNESCAPED_UNICODE)json_decodetools.php-function-query.categories.json
将 JSON 字符串解码为 PHP 变量。
tools.php-function-query.labels.syntax
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedtools.php-function-query.labels.example
json_decode('{"a":1}', true) // ['a'=>1]json_last_errortools.php-function-query.categories.json
返回最近一次 JSON 操作的错误码。
tools.php-function-query.labels.syntax
json_last_error(): inttools.php-function-query.labels.example
if (json_last_error() !== JSON_ERROR_NONE) { ... }urlencodetools.php-function-query.categories.url
对字符串按 application/x-www-form-urlencoded 进行编码。
tools.php-function-query.labels.syntax
urlencode(string $string): stringtools.php-function-query.labels.example
urlencode('hello world') // 'hello+world'urldecodetools.php-function-query.categories.url
对 urlencoded 字符串进行解码。
tools.php-function-query.labels.syntax
urldecode(string $string): stringtools.php-function-query.labels.example
urldecode('a%20b') // 'a b'rawurlencodetools.php-function-query.categories.url
按 RFC 3986 对字符串进行 URL 编码(空格变 %20)。
tools.php-function-query.labels.syntax
rawurlencode(string $string): stringtools.php-function-query.labels.example
rawurlencode('a b') // 'a%20b'parse_urltools.php-function-query.categories.url
解析 URL,返回各个组成部分。
tools.php-function-query.labels.syntax
parse_url(string $url, int $component = -1): array|string|int|null|falsetools.php-function-query.labels.example
parse_url('https://a.com/b?c=1') // ['scheme'=>'https',...]http_build_querytools.php-function-query.categories.url
由数组生成 URL 编码后的查询字符串。
tools.php-function-query.labels.syntax
http_build_query(array|object $data, string $numeric_prefix = '', ?string $arg_separator = null, int $encoding_type = PHP_QUERY_RFC1738): stringtools.php-function-query.labels.example
http_build_query(['a'=>1,'b'=>2]) // 'a=1&b=2'base64_encodetools.php-function-query.categories.url
对字符串进行 Base64 编码。
tools.php-function-query.labels.syntax
base64_encode(string $string): stringtools.php-function-query.labels.example
base64_encode('hello') // 'aGVsbG8='base64_decodetools.php-function-query.categories.url
对 Base64 字符串进行解码。
tools.php-function-query.labels.syntax
base64_decode(string $string, bool $strict = false): string|falsetools.php-function-query.labels.example
base64_decode('aGVsbG8=') // 'hello'md5tools.php-function-query.categories.hash
计算字符串的 MD5 散列值(32 位十六进制)。
tools.php-function-query.labels.syntax
md5(string $string, bool $binary = false): stringtools.php-function-query.labels.example
md5('hello') // '5d41402abc4b2a76b9719d911017c592'不安全用于密码存储,请使用 password_hash。
sha1tools.php-function-query.categories.hash
计算字符串的 SHA1 散列值。
tools.php-function-query.labels.syntax
sha1(string $string, bool $binary = false): stringtools.php-function-query.labels.example
sha1('hello')hashtools.php-function-query.categories.hash
通用散列函数,支持多种算法。
tools.php-function-query.labels.syntax
hash(string $algo, string $data, bool $binary = false): stringtools.php-function-query.labels.example
hash('sha256', $data)hash_hmactools.php-function-query.categories.hash
使用 HMAC 算法生成带密钥的散列。
tools.php-function-query.labels.syntax
hash_hmac(string $algo, string $data, string $key, bool $binary = false): stringtools.php-function-query.labels.example
hash_hmac('sha256', $data, $secret)password_hashtools.php-function-query.categories.hash
用安全的算法(bcrypt/argon2)生成密码哈希。
tools.php-function-query.labels.syntax
password_hash(string $password, string|int|null $algo, array $options = []): stringtools.php-function-query.labels.example
password_hash($pw, PASSWORD_DEFAULT)存储用户密码时优先使用此函数。
password_verifytools.php-function-query.categories.hash
校验密码是否匹配 password_hash 生成的哈希。
tools.php-function-query.labels.syntax
password_verify(string $password, string $hash): booltools.php-function-query.labels.example
password_verify($input, $stored)crc32tools.php-function-query.categories.hash
计算字符串的 CRC32 校验和。
tools.php-function-query.labels.syntax
crc32(string $string): inttools.php-function-query.labels.example
crc32('hello')curl_inittools.php-function-query.categories.network
初始化一个 cURL 会话。
tools.php-function-query.labels.syntax
curl_init(?string $url = null): CurlHandle|falsetools.php-function-query.labels.example
$ch = curl_init('https://api.example.com')curl_setopttools.php-function-query.categories.network
设置 cURL 会话选项。
tools.php-function-query.labels.syntax
curl_setopt(CurlHandle $handle, int $option, mixed $value): booltools.php-function-query.labels.example
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)curl_exectools.php-function-query.categories.network
执行 cURL 会话并返回结果。
tools.php-function-query.labels.syntax
curl_exec(CurlHandle $handle): string|booltools.php-function-query.labels.example
$body = curl_exec($ch)curl_closetools.php-function-query.categories.network
关闭 cURL 会话并释放资源。
tools.php-function-query.labels.syntax
curl_close(CurlHandle $handle): voidtools.php-function-query.labels.example
curl_close($ch)headertools.php-function-query.categories.network
发送原始 HTTP 头到客户端,须在任何输出之前调用。
tools.php-function-query.labels.syntax
header(string $header, bool $replace = true, int $response_code = 0): voidtools.php-function-query.labels.example
header('Content-Type: application/json')setcookietools.php-function-query.categories.network
向客户端发送 Cookie。
tools.php-function-query.labels.syntax
setcookie(string $name, string $value = '', int $expires_or_options = 0, string $path = '', string $domain = '', bool $secure = false, bool $httponly = false): booltools.php-function-query.labels.example
setcookie('uid', $uid, time()+3600, '/', '', true, true)session_starttools.php-function-query.categories.session
启动新会话或恢复现有会话。
tools.php-function-query.labels.syntax
session_start(array $options = []): booltools.php-function-query.labels.example
session_start()session_destroytools.php-function-query.categories.session
销毁当前会话的全部数据。
tools.php-function-query.labels.syntax
session_destroy(): booltools.php-function-query.labels.example
session_destroy()session_idtools.php-function-query.categories.session
获取或设置当前会话 ID。
tools.php-function-query.labels.syntax
session_id(?string $id = null): string|falsetools.php-function-query.labels.example
session_id()session_regenerate_idtools.php-function-query.categories.session
更新当前会话 ID 并可选删除旧会话。
tools.php-function-query.labels.syntax
session_regenerate_id(bool $delete_old_session = false): booltools.php-function-query.labels.example
session_regenerate_id(true)class_existstools.php-function-query.categories.class
检查类是否已定义。
tools.php-function-query.labels.syntax
class_exists(string $class, bool $autoload = true): booltools.php-function-query.labels.example
class_exists('App\\User')get_classtools.php-function-query.categories.class
返回对象所属的类名。
tools.php-function-query.labels.syntax
get_class(?object $object = null): stringtools.php-function-query.labels.example
get_class($user) // 'App\\User'method_existstools.php-function-query.categories.class
检查类或对象是否存在指定方法。
tools.php-function-query.labels.syntax
method_exists(object|string $object_or_class, string $method): booltools.php-function-query.labels.example
method_exists($obj, 'save')property_existstools.php-function-query.categories.class
检查对象或类是否存在指定属性。
tools.php-function-query.labels.syntax
property_exists(object|string $object_or_class, string $property): booltools.php-function-query.labels.example
property_exists($user, 'email')is_atools.php-function-query.categories.class
判断对象是否是给定类的实例或子类。
tools.php-function-query.labels.syntax
is_a(mixed $object_or_class, string $class, bool $allow_string = false): booltools.php-function-query.labels.example
is_a($user, User::class)instanceoftools.php-function-query.categories.class
运算符,判断对象是否属于某个类或实现某接口。
tools.php-function-query.labels.syntax
$obj instanceof ClassNametools.php-function-query.labels.example
if ($e instanceof \Exception) { ... }instanceof 是语言结构,非函数。
call_user_functools.php-function-query.categories.class
调用一个回调,包括函数名、闭包或方法数组。
tools.php-function-query.labels.syntax
call_user_func(callable $callback, mixed ...$args): mixedtools.php-function-query.labels.example
call_user_func([$obj,'method'], $arg)dietools.php-function-query.categories.other
输出消息并终止脚本,与 exit 等价。
tools.php-function-query.labels.syntax
die(string|int $status = ''): voidtools.php-function-query.labels.example
die('error')exittools.php-function-query.categories.other
终止脚本执行,可输出消息或返回退出码。
tools.php-function-query.labels.syntax
exit(string|int $status = ''): voidtools.php-function-query.labels.example
exit(0)error_reportingtools.php-function-query.categories.other
设置 PHP 的错误报告级别。
tools.php-function-query.labels.syntax
error_reporting(?int $error_level = null): inttools.php-function-query.labels.example
error_reporting(E_ALL)ini_gettools.php-function-query.categories.other
获取 php.ini 配置项的值。
tools.php-function-query.labels.syntax
ini_get(string $option): string|falsetools.php-function-query.labels.example
ini_get('upload_max_filesize')ini_settools.php-function-query.categories.other
在运行时修改 php.ini 配置项。
tools.php-function-query.labels.syntax
ini_set(string $option, string|int|float|bool|null $value): string|falsetools.php-function-query.labels.example
ini_set('memory_limit', '256M')phpversiontools.php-function-query.categories.other
返回当前运行的 PHP 版本。
tools.php-function-query.labels.syntax
phpversion(?string $extension = null): string|falsetools.php-function-query.labels.example
phpversion() // '8.2.0'function_existstools.php-function-query.categories.other
判断函数是否已定义。
tools.php-function-query.labels.syntax
function_exists(string $function): booltools.php-function-query.labels.example
if (function_exists('mb_strlen')) { ... }definedtools.php-function-query.categories.other
判断常量是否已被定义。
tools.php-function-query.labels.syntax
defined(string $constant_name): booltools.php-function-query.labels.example
defined('APP_ENV')definetools.php-function-query.categories.other
定义一个常量。
tools.php-function-query.labels.syntax
define(string $constant_name, mixed $value, bool $case_insensitive = false): booltools.php-function-query.labels.example
define('APP_ENV', 'production')sleeptools.php-function-query.categories.other
让脚本暂停指定秒数。
tools.php-function-query.labels.syntax
sleep(int $seconds): inttools.php-function-query.labels.example
sleep(2)usleeptools.php-function-query.categories.other
让脚本暂停指定微秒数。
tools.php-function-query.labels.syntax
usleep(int $microseconds): voidtools.php-function-query.labels.example
usleep(500000) // 暂停 0.5 秒