首页 后端开发 php教程 [PHP]PHP函数

[PHP]PHP函数

Jul 29, 2016 am 09:15 AM
php



字符串 STRING


>> 统计

strlen(string) - 长度

strcmp(string1,string2) - 比较字符串

>> 查找

strpos(string,find,start) - 在另一个字符串中查找, 返回第一次位置

    stripos(string,find,start) - (大小写不敏感)

    strrpos(string,find,start) - (最后一次)

    strripos(string,find,start) - (大小写不敏感)(最后一次)

strstr(string,search) - 在另一个字符串中匹配, 返回第一次匹配值及剩余部分

    stristr(string,search) - (大小写不敏感)

str_replace(find,replace,string,count) - 替换

    str_ireplace(find,replace,string,count) - (大小写不敏感)

substr(string,start,length) - 截取

>> 转换

explode(separator,string,limit) - 字符串 -> 数组

    implode(separator, array) - 数组 -> 字符串

    join(separator,array) - 同上

str_split(string,length) - 字符串分割为数组

parse_str(string,array) - 解析Query串为数组

strtolower(string) - 小写

    strtoupper(string) - 大写

str_shuffle(string) - 随机打散

strrev(string) - 反转

>> 输出

echo(string)

    print(string)

    printf(format,arg1,arg2,arg++) - 格式化输出

    fprintf(stream,format,arg1,arg2,arg++) - 格式化输出到文件

    sprintf(format,arg1,arg2,arg++) - 格式化到字符串

>> 格式化

str_pad(string,length,pad_string,pad_type) - 填充到指定长度

str_repeat(string,repeat) - 重复指定次数

chunk_split(string,length,end) - 插入分隔符

number_format(number,decimals,decimalpoint,separator) - 格式化数字

trim(string,charlist) - 两端清理

strip_tags(string,allow) - 剥离HTML, XML, PHP标签

>> 转义

addslashes(string) - 在预定义字符前添加反斜杠

    stripslashes(string)

    addcslashes(string,characters) - 在自定义字符前添加反斜杠

    stripcslashes(string)

htmlentities(string,quotestyle,character-set) - 全部字符 -> HTML实体

    html_entity_decode(string,quotestyle,character-set) - HTML实体 -> 字符

    htmlspecialchars(string,quotestyle,character-set) - 部分字符( & | " | ' | ) -> HTML实体

    htmlspecialchars_decode(string,quotestyle) - HTML实体 -> 字符

nl2br(string) - /n ->

>> 加密

crypt(str,salt) - 单向有损加密

    md5(string,raw) - 散列

        md5_file(path,raw) - 文件有损摘要

    sha1(string,raw) - SHA1散列

        sha1_file(file,raw)

>> ASCII

ord(string) - 返回第一个字符的ASCII

数组 ARRAY


>> 新建&赋值

list(var1,var2,val3...) = $array - 用数组元素给变量赋值

range(min,max,step) - 建立指定范围的数组

array_combine(array1,array2) - 新建数组:array1为key,array2为value

>> 栈

array_pop(array) - 尾部出栈

array_push(array,value1,value2...) - 尾部入栈,相当于$array[] = $value

array_shift(array) - 首部出栈

array_unshift(array,value1,value2,value3...) - 首部入栈

>> 统计

array_sum(array) - 所有元素的和

array_product(array) - 所有元素的乘积

count(array,mode) - 统计元素个数,同 sizeof(array,mode)

array_count_values(array)  - 统计元素出现次数

array_keys(array,value,strict) - 返回对应的key

array_values(array) - 返回所有value

array_search(value,array,strict) - 搜索value,返回key

in_array(value,array,type) - 检查value是否存在

array_key_exists(key,array) - 检查key是否存在

>> 比较

array_diff(array1,array2,array3...) - 差集

    array_diff_assoc(array1,array2,array3...)

    array_diff_key(array1,array2,array3...)

array_intersect(array1,array2,array3...) - 交集

    array_intersect_assoc(array1,array2,array3...)

    array_intersect_key(array1,array2,array3...)

>>排序

sort(array,sorttype) - 按value升序排序(重建索引)

    rsort(array,sorttype) - 按value降序排序(重建索引)

    asort(array,sorttype) - 按value正向排序(保持索引)

    arsort(array,sorttype) - 按value逆向排序(保持索引)

    natsort(array) - 自然排序

    natcasesort(array) - 不区分大小自然排序

ksort(array,sorttype) - 按key正向排序

    krsort(array,sorttype) - 按key逆向排序

array_multisort(array,sorting order,sorting type) - 排序

shuffle(array) - 随机打乱数组排序

array_reverse(array,preserve) - 顺序反转

>> 修改

array_change_key_case(array,case) - 转换大小写

array_filter(array,function) - 用给定方法过滤

array_map(function,array1,array2,array3...) - 将方法用于每个元素

array_fill(start,number,value) - 用给定值填充数组

array_pad(array,size,value) - 把数组补到定长

array_flip(array) - 交换key和value

array_unique(array) - 去重

>> 合并&分割

array_chunk(array,size,preserve_key) - 切割

array_rand(array,number) - 随机返回数组元素(number=1时返回key)

array_slice(array,offset,length,preserve) - 截取

array_splice(array,offset,length,array) - 替换

array_merge(array1,array2,array3...) - 合并

    array_merge_recursive(array1,array2,array3...) - 递归合并(key相同时)

>> 指针

each(array) - 返回当前元素,并移动指针

key(array) - 当前key

current(array) - 当前value,同 pos(array)

next(array) - 下一个value

prev(array) - 上一个value

reset(array) - 移到首部

end(array) - 移到末尾

日期时间 DATE & TIME


checkdate(month,day,year) - 检查日期合法性

date(format,timestamp) - 格式化输出时间

>> 信息

getdate(timestamp) - 获取日期&时间信息数组

microtime(get_as_float) - 获取当前时间信息数组

>> 时间戳

time() - 当前时间时间戳

strtotime(time,now) - 字符串转换为时间戳

mktime(hour,minute,second,month,day,year,is_dst) - 获取时间戳

目录 DIR


opendir(path,context) - 打开目录,返回句柄

    readdir(handle) - 返回文件名

    closedir(handle) - 关闭句柄

    rewinddir(handle) - 重置句柄

dir(directory) - 打开目录,返回对象,该对象有read(),rewind(),close() 3个方法

文件 FILE


clearstatcache() - 清除文件缓存状态

parse_ini_file(file,process_sections) - 解析ini文件,返回数组

set_file_buffer(file,buffer) - 设置文件输出缓冲

>> 文件操作

readfile(filename,include_path,context) - 读取文件,并输出到缓冲区

    readlink(linkpath)

file(path,include_path,context) - 以数组方式读取文件

file_get_contents(path,include_path,context,start,max_length) - 读取文件到字符串

    file_put_contents(path,data,mode,context) - 写入文件

fopen(filename,mode,include_path,context) - 打开文件

    fgetc(file) - 读取字符

    fgets(file,length) - 读取一行,或指定长度

        fgetcsv(file,length,separator,enclosure) - 按CSV格式读取一行

    fputs(file,string,length) - 写文件

        fputcsv(file,fields,seperator,enclosure) - 按CSV格式写入文件

    fread(file,length) - 读取文件

    fwrite(file,string,length) - 写入文件

    fflush(file) - 输出缓冲内容到文件

    ftruncate(file,size) - 截取文件

    flock(file,lock,block) - 锁定文件

    ftell(file) - 指针位置

    fseek(file,offset,whence) - 定位指针

    rewind(file) - 重置指针位置

    feof(file) - 是否到达文件结尾

    fstat(file) - 文件信息

    fclose(file) - 关闭

tmpfile() - 创建临时文件,在fclose后删除

popen(command,mode) - 打开指向进程的管道

    pclose(pipe)

>> 文件状态

fstat(file) - 文件信息

    lstat(file) - 文件/软连接信息

fileatime(filename) - 上次访问时间

filectime(filename) - 上次inode信息修改时间

filemtime(filename) - 上次文件内容修改时间

filegroup(filename) - 文件用户组

fileowner(filename) - 文件用户

fileperms(filename) - 文件权限

fileinode(filename) - 文件inode

filesize(filename) - 文件大小

filetype(filename) - 文件类型

>> 路径

pathinfo(path,options) - 路径信息

    linkinfo(path) - 硬连接信息

basename(path,suffix) - 取文件名

dirname(path) - 取目录路径

realpath(path) - 取绝对路径

>> 大小

disk_total_space(directory) - 总空间大小

disk_free_space(directory) - 可用空间大小

>> 判断

file_exists(path) - 文件或目录是否存在

is_dir(path) - 目录

is_file(path) - 文件

is_link(path) - 连接

is_readable(path) - 可读

is_writable(path) - 可写

is_executable(path) - 可执行

>> 系统

mkdir(path,mode,recursive,context)

rmdir(dir,context)

link(target,link)

unlink(filename,context)

copy(source,destination)

rename(oldname,newname,context)

touch(filename,time,atime)

chgrp(filename,group)

chmod(filename,mode)

chown(filename,owner)

glob(pattern,flags)

>> HTTP POST

is_uploaded_file(filename) - 文件是否通过HTTP POST上传

move_uploaded_file(filename,newloc) - 移动上传的文件

错误和异常 ERROR & EXCEPTION


debug_backtrace() - 生成backtrace关联数组

    debug_print_backtrace() - 输出

error_get_last() - 获取最底层的错误

error_log(error,type,destination,headers) - 错误日志

error_reporting(report_level) - 设置错误报告级别

>> 触发错误/抛出异常

trigger_error(error_message,error_types) - 触发错误

throw new Exception() - 抛出异常

>> 指定处理函数

set_error_handler(error_function,error_types) - 错误处理函数

set_exception_handler(exception_function) - 异常处理函数

过滤器 FILTER


filter_has_var(type, variable) - 是否有该变量

filter_input(input_type, variable, filter, options) - 过滤外部输入

    filter_input_array(input_type, args)

filter_var(variable, filter, options) - 过滤变量

    filter_var_array(array, args)

>> Filter

SANITIZE(过滤)

    FILTER_SANITIZE_STRING - 去除或编码特殊字符

    FILTER_SANITIZE_ENCODED - 类似于urlendode

    FILTER_SANITIZE_SPECIAL_CHARS - 类似于urlendode

    FILTER_SANITIZE_MAGIC_QUOTES - 似于addslashes

    FILTER_SANITIZE_URL

    FILTER_SANITIZE_EMAIL

    FILTER_SANITIZE_NUMBER_INT

    FILTER_SANITIZE_NUMBER_FLOAT

VALIDATE(验证)

    FILTER_VALIDATE_BOOLEAN

    FILTER_VALIDATE_INT

    FILTER_VALIDATE_FLOAT

    FILTER_VALIDATE_URL

    FILTER_VALIDATE_EMAIL

    FILTER_VALIDATE_IP

    FILTER_VALIDATE_REGEXP

FILTER_CALLBACK - 调用自定义函数

文件传输 FTP


>> 连接

ftp_connect(host,port,timeout) - 建立连接

    ftp_ssl_connect(host,port,timeout) - SSL安全连接

    

    ftp_login(ftp_connection,username,password) - 登陆FTP

    ftp_raw(ftp_connection,command) - 发送命令

        ftp_exec(ftp_connection,command) - 执行命令(登陆后)

    ftp_pasv(ftp_connection,mode) - 是否被动模式

    ftp_systype(ftp_connection) - 远程机器系统

    ftp_get_option(ftp_connection,option) - 获取参数

        ftp_set_option(ftp_connection,option,value) - 设置选项

    ftp_close(ftp_connection) - 关闭连接,同 ftp_quit()

>> 目录

ftp_mkdir(ftp_connection,dir) - 建立目录

ftp_rmdir(ftp_connection,dir) - 删除目录

ftp_chdir(ftp_connection,dir) - 改变目录

ftp_cdup(ftp_connection) - 父目录

ftp_pwd(ftp_connection) - 当前路径
ftp_nlist(ftp_connection,dir) - 列目录

    ftp_rawlist(ftp_connection,dir,recursive) - 目录列表详情

>> 文件

ftp_put(ftp_connection,remote,local,mode,resume) - 上传文件

    ftp_fput(ftp_connection,remote,local,mode,resume) - 上传本地打开文件

    ftp_nb_put(ftp_connection,remote,local,mode,resume) - 异步上传

    ftp_nb_fput(ftp_connection,remote,local,mode,resume) - 异步上传本地打开文件

ftp_get(ftp_connection,local,remote,mode,resume) - 下载文件

    ftp_fget(ftp_connection,local,remote,mode,resume) - 下载到本地打开文件

    ftp_nb_get(ftp_connection,local,remote,mode,resume) - 异步下载

    ftp_nb_fget(ftp_connection,local,remote,mode,resume) - 异步下载到本地打开文件

ftp_delete(ftp_connection,path) - 删除文件

ftp_rename(ftp_connection,from,to) - 重命名

ftp_chmod(ftp_connection,mode,file) - 改变文件权限

ftp_size(ftp_connection,remote_file) - 文件大小

ftp_mdtm(ftp_connection,file) - 文件最后修改时间

HTTP


header(string,replace,http_response_code) - 发送HTTP报头

    headers_list() - 报头列表数组

    headers_sent() - 是否已发送报头

setcookie(name,value,expire,path,domain,secure) - 设置Cookie

数学 MATH


>> 算数

round() - 四舍五入

    ceil() - 向上取整

    floor() - 向下取整

max() - 返回最大值

    min() - 返回最小值

pow(x,y) - x的y次方

    sqrt() - 平方根

abs() - 绝对值

rand(min,max) - 返回随机整数

>> 进制

base_convert(number,frombase,tobase) - 任意进制转换

decbin() - 十进制 -> 二进制

    bindec(binary_string) - 二进制 -> 十进制

dechex() - 十进制 -> 十六进制

    hexdec() - 十六进制 -> 十进制

decoct() - 十进制 -> 八进制

    octdec() - 八进制 -> 十进制

>> 三角函数

cos() - 余弦

    acos() - 反余弦

sin() - 正弦

    asin() - 反正弦

tan() - 正切

    atan() -  - 反正切

MySQL


>> 连接

mysql_connect(server,user,pwd,newlink,clientflag) - 连接

    mysql_pconnect(server,user,pwd,clientflag) - 长连接

    mysql_close(connection) - 关闭

>> 查询

mysql_select_db(database,connection) - 选择数据库

mysql_query(sql) - 执行查询,返回资源句柄

mysql_fetch_array(data,array_type) - 查询, 返回数组

    mysql_fetch_assoc(data) - 返回关联数组

mysql_fetch_object(data) - 查询, 返回对象

mysql_num_rows(data) -  结果行数

>> 连接状态

mysql_ping(connection) - 检查连接, 断开则重连

mysql_thread_id(connection) - 当前连接ID

mysql_client_encoding(connection) - 当前字符集

mysql_list_dbs(connection) - 列出数据库

>> 上次操作

mysql_info(connection) - 上次查询的信息

mysql_affected_rows(connection) - 影响行数

mysql_insert_id(connection) - 上次插入的ID

mysql_errno(connection) - 上次错误ID

    mysql_error(connection) - 上次错误信息

输入输出 I/O


>> 打印

print_r(value)

    var_dump(value) - 带类型

    var_export(value) - 返回合法的PHP代码

出处

[PHP]PHP函数

字符串 STRING


>> 统计

strlen(string) - 长度

strcmp(string1,string2) - 比较字符串

>> 查找

strpos(string,find,start) - 在另一个字符串中查找, 返回第一次位置

    stripos(string,find,start) - (大小写不敏感)

    strrpos(string,find,start) - (最后一次)

    strripos(string,find,start) - (大小写不敏感)(最后一次)

strstr(string,search) - 在另一个字符串中匹配, 返回第一次匹配值及剩余部分

    stristr(string,search) - (大小写不敏感)

str_replace(find,replace,string,count) - 替换

    str_ireplace(find,replace,string,count) - (大小写不敏感)

substr(string,start,length) - 截取

>> 转换

explode(separator,string,limit) - 字符串 -> 数组

    implode(separator, array) - 数组 -> 字符串

    join(separator,array) - 同上

str_split(string,length) - 字符串分割为数组

parse_str(string,array) - 解析Query串为数组

strtolower(string) - 小写

    strtoupper(string) - 大写

str_shuffle(string) - 随机打散

strrev(string) - 反转

>> 输出

echo(string)

    print(string)

    printf(format,arg1,arg2,arg++) - 格式化输出

    fprintf(stream,format,arg1,arg2,arg++) - 格式化输出到文件

    sprintf(format,arg1,arg2,arg++) - 格式化到字符串

>> 格式化

str_pad(string,length,pad_string,pad_type) - 填充到指定长度

str_repeat(string,repeat) - 重复指定次数

chunk_split(string,length,end) - 插入分隔符

number_format(number,decimals,decimalpoint,separator) - 格式化数字

trim(string,charlist) - 两端清理

strip_tags(string,allow) - 剥离HTML, XML, PHP标签

>> 转义

addslashes(string) - 在预定义字符前添加反斜杠

    stripslashes(string)

    addcslashes(string,characters) - 在自定义字符前添加反斜杠

    stripcslashes(string)

htmlentities(string,quotestyle,character-set) - 全部字符 -> HTML实体

    html_entity_decode(string,quotestyle,character-set) - HTML实体 -> 字符

    htmlspecialchars(string,quotestyle,character-set) - 部分字符( & | " | ' | ) -> HTML实体

    htmlspecialchars_decode(string,quotestyle) - HTML实体 -> 字符

nl2br(string) - /n ->

>> 加密

crypt(str,salt) - 单向有损加密

    md5(string,raw) - 散列

        md5_file(path,raw) - 文件有损摘要

    sha1(string,raw) - SHA1散列

        sha1_file(file,raw)

>> ASCII

ord(string) - 返回第一个字符的ASCII

数组 ARRAY


>> 新建&赋值

list(var1,var2,val3...) = $array - 用数组元素给变量赋值

range(min,max,step) - 建立指定范围的数组

array_combine(array1,array2) - 新建数组:array1为key,array2为value

>> 栈

array_pop(array) - 尾部出栈

array_push(array,value1,value2...) - 尾部入栈,相当于$array[] = $value

array_shift(array) - 首部出栈

array_unshift(array,value1,value2,value3...) - 首部入栈

>> 统计

array_sum(array) - 所有元素的和

array_product(array) - 所有元素的乘积

count(array,mode) - 统计元素个数,同 sizeof(array,mode)

array_count_values(array)  - 统计元素出现次数

array_keys(array,value,strict) - 返回对应的key

array_values(array) - 返回所有value

array_search(value,array,strict) - 搜索value,返回key

in_array(value,array,type) - 检查value是否存在

array_key_exists(key,array) - 检查key是否存在

>> 比较

array_diff(array1,array2,array3...) - 差集

    array_diff_assoc(array1,array2,array3...)

    array_diff_key(array1,array2,array3...)

array_intersect(array1,array2,array3...) - 交集

    array_intersect_assoc(array1,array2,array3...)

    array_intersect_key(array1,array2,array3...)

>>排序

sort(array,sorttype) - 按value升序排序(重建索引)

    rsort(array,sorttype) - 按value降序排序(重建索引)

    asort(array,sorttype) - 按value正向排序(保持索引)

    arsort(array,sorttype) - 按value逆向排序(保持索引)

    natsort(array) - 自然排序

    natcasesort(array) - 不区分大小自然排序

ksort(array,sorttype) - 按key正向排序

    krsort(array,sorttype) - 按key逆向排序

array_multisort(array,sorting order,sorting type) - 排序

shuffle(array) - 随机打乱数组排序

array_reverse(array,preserve) - 顺序反转

>> 修改

array_change_key_case(array,case) - 转换大小写

array_filter(array,function) - 用给定方法过滤

array_map(function,array1,array2,array3...) - 将方法用于每个元素

array_fill(start,number,value) - 用给定值填充数组

array_pad(array,size,value) - 把数组补到定长

array_flip(array) - 交换key和value

array_unique(array) - 去重

>> 合并&分割

array_chunk(array,size,preserve_key) - 切割

array_rand(array,number) - 随机返回数组元素(number=1时返回key)

array_slice(array,offset,length,preserve) - 截取

array_splice(array,offset,length,array) - 替换

array_merge(array1,array2,array3...) - 合并

    array_merge_recursive(array1,array2,array3...) - 递归合并(key相同时)

>> 指针

each(array) - 返回当前元素,并移动指针

key(array) - 当前key

current(array) - 当前value,同 pos(array)

next(array) - 下一个value

prev(array) - 上一个value

reset(array) - 移到首部

end(array) - 移到末尾

日期时间 DATE & TIME


checkdate(month,day,year) - 检查日期合法性

date(format,timestamp) - 格式化输出时间

>> 信息

getdate(timestamp) - 获取日期&时间信息数组

microtime(get_as_float) - 获取当前时间信息数组

>> 时间戳

time() - 当前时间时间戳

strtotime(time,now) - 字符串转换为时间戳

mktime(hour,minute,second,month,day,year,is_dst) - 获取时间戳

目录 DIR


opendir(path,context) - 打开目录,返回句柄

    readdir(handle) - 返回文件名

    closedir(handle) - 关闭句柄

    rewinddir(handle) - 重置句柄

dir(directory) - 打开目录,返回对象,该对象有read(),rewind(),close() 3个方法

文件 FILE


clearstatcache() - 清除文件缓存状态

parse_ini_file(file,process_sections) - 解析ini文件,返回数组

set_file_buffer(file,buffer) - 设置文件输出缓冲

>> 文件操作

readfile(filename,include_path,context) - 读取文件,并输出到缓冲区

    readlink(linkpath)

file(path,include_path,context) - 以数组方式读取文件

file_get_contents(path,include_path,context,start,max_length) - 读取文件到字符串

    file_put_contents(path,data,mode,context) - 写入文件

fopen(filename,mode,include_path,context) - 打开文件

    fgetc(file) - 读取字符

    fgets(file,length) - 读取一行,或指定长度

        fgetcsv(file,length,separator,enclosure) - 按CSV格式读取一行

    fputs(file,string,length) - 写文件

        fputcsv(file,fields,seperator,enclosure) - 按CSV格式写入文件

    fread(file,length) - 读取文件

    fwrite(file,string,length) - 写入文件

    fflush(file) - 输出缓冲内容到文件

    ftruncate(file,size) - 截取文件

    flock(file,lock,block) - 锁定文件

    ftell(file) - 指针位置

    fseek(file,offset,whence) - 定位指针

    rewind(file) - 重置指针位置

    feof(file) - 是否到达文件结尾

    fstat(file) - 文件信息

    fclose(file) - 关闭

tmpfile() - 创建临时文件,在fclose后删除

popen(command,mode) - 打开指向进程的管道

    pclose(pipe)

>> 文件状态

fstat(file) - 文件信息

    lstat(file) - 文件/软连接信息

fileatime(filename) - 上次访问时间

filectime(filename) - 上次inode信息修改时间

filemtime(filename) - 上次文件内容修改时间

filegroup(filename) - 文件用户组

fileowner(filename) - 文件用户

fileperms(filename) - 文件权限

fileinode(filename) - 文件inode

filesize(filename) - 文件大小

filetype(filename) - 文件类型

>> 路径

pathinfo(path,options) - 路径信息

    linkinfo(path) - 硬连接信息

basename(path,suffix) - 取文件名

dirname(path) - 取目录路径

realpath(path) - 取绝对路径

>> 大小

disk_total_space(directory) - 总空间大小

disk_free_space(directory) - 可用空间大小

>> 判断

file_exists(path) - 文件或目录是否存在

is_dir(path) - 目录

is_file(path) - 文件

is_link(path) - 连接

is_readable(path) - 可读

is_writable(path) - 可写

is_executable(path) - 可执行

>> 系统

mkdir(path,mode,recursive,context)

rmdir(dir,context)

link(target,link)

unlink(filename,context)

copy(source,destination)

rename(oldname,newname,context)

touch(filename,time,atime)

chgrp(filename,group)

chmod(filename,mode)

chown(filename,owner)

glob(pattern,flags)

>> HTTP POST

is_uploaded_file(filename) - 文件是否通过HTTP POST上传

move_uploaded_file(filename,newloc) - 移动上传的文件

错误和异常 ERROR & EXCEPTION


debug_backtrace() - 生成backtrace关联数组

    debug_print_backtrace() - 输出

error_get_last() - 获取最底层的错误

error_log(error,type,destination,headers) - 错误日志

error_reporting(report_level) - 设置错误报告级别

>> 触发错误/抛出异常

trigger_error(error_message,error_types) - 触发错误

throw new Exception() - 抛出异常

>> 指定处理函数

set_error_handler(error_function,error_types) - 错误处理函数

set_exception_handler(exception_function) - 异常处理函数

过滤器 FILTER


filter_has_var(type, variable) - 是否有该变量

filter_input(input_type, variable, filter, options) - 过滤外部输入

    filter_input_array(input_type, args)

filter_var(variable, filter, options) - 过滤变量

    filter_var_array(array, args)

>> Filter

SANITIZE(过滤)

    FILTER_SANITIZE_STRING - 去除或编码特殊字符

    FILTER_SANITIZE_ENCODED - 类似于urlendode

    FILTER_SANITIZE_SPECIAL_CHARS - 类似于urlendode

    FILTER_SANITIZE_MAGIC_QUOTES - 似于addslashes

    FILTER_SANITIZE_URL

    FILTER_SANITIZE_EMAIL

    FILTER_SANITIZE_NUMBER_INT

    FILTER_SANITIZE_NUMBER_FLOAT

VALIDATE(验证)

    FILTER_VALIDATE_BOOLEAN

    FILTER_VALIDATE_INT

    FILTER_VALIDATE_FLOAT

    FILTER_VALIDATE_URL

    FILTER_VALIDATE_EMAIL

    FILTER_VALIDATE_IP

    FILTER_VALIDATE_REGEXP

FILTER_CALLBACK - 调用自定义函数

文件传输 FTP


>> 连接

ftp_connect(host,port,timeout) - 建立连接

    ftp_ssl_connect(host,port,timeout) - SSL安全连接

    

    ftp_login(ftp_connection,username,password) - 登陆FTP

    ftp_raw(ftp_connection,command) - 发送命令

        ftp_exec(ftp_connection,command) - 执行命令(登陆后)

    ftp_pasv(ftp_connection,mode) - 是否被动模式

    ftp_systype(ftp_connection) - 远程机器系统

    ftp_get_option(ftp_connection,option) - 获取参数

        ftp_set_option(ftp_connection,option,value) - 设置选项

    ftp_close(ftp_connection) - 关闭连接,同 ftp_quit()

>> 目录

ftp_mkdir(ftp_connection,dir) - 建立目录

ftp_rmdir(ftp_connection,dir) - 删除目录

ftp_chdir(ftp_connection,dir) - 改变目录

ftp_cdup(ftp_connection) - 父目录

ftp_pwd(ftp_connection) - 当前路径
ftp_nlist(ftp_connection,dir) - 列目录

    ftp_rawlist(ftp_connection,dir,recursive) - 目录列表详情

>> 文件

ftp_put(ftp_connection,remote,local,mode,resume) - 上传文件

    ftp_fput(ftp_connection,remote,local,mode,resume) - 上传本地打开文件

    ftp_nb_put(ftp_connection,remote,local,mode,resume) - 异步上传

    ftp_nb_fput(ftp_connection,remote,local,mode,resume) - 异步上传本地打开文件

ftp_get(ftp_connection,local,remote,mode,resume) - 下载文件

    ftp_fget(ftp_connection,local,remote,mode,resume) - 下载到本地打开文件

    ftp_nb_get(ftp_connection,local,remote,mode,resume) - 异步下载

    ftp_nb_fget(ftp_connection,local,remote,mode,resume) - 异步下载到本地打开文件

ftp_delete(ftp_connection,path) - 删除文件

ftp_rename(ftp_connection,from,to) - 重命名

ftp_chmod(ftp_connection,mode,file) - 改变文件权限

ftp_size(ftp_connection,remote_file) - 文件大小

ftp_mdtm(ftp_connection,file) - 文件最后修改时间

HTTP


header(string,replace,http_response_code) - 发送HTTP报头

    headers_list() - 报头列表数组

    headers_sent() - 是否已发送报头

setcookie(name,value,expire,path,domain,secure) - 设置Cookie

数学 MATH


>> 算数

round() - 四舍五入

    ceil() - 向上取整

    floor() - 向下取整

max() - 返回最大值

    min() - 返回最小值

pow(x,y) - x的y次方

    sqrt() - 平方根

abs() - 绝对值

rand(min,max) - 返回随机整数

>> 进制

base_convert(number,frombase,tobase) - 任意进制转换

decbin() - 十进制 -> 二进制

    bindec(binary_string) - 二进制 -> 十进制

dechex() - 十进制 -> 十六进制

    hexdec() - 十六进制 -> 十进制

decoct() - 十进制 -> 八进制

    octdec() - 八进制 -> 十进制

>> 三角函数

cos() - 余弦

    acos() - 反余弦

sin() - 正弦

    asin() - 反正弦

tan() - 正切

    atan() -  - 反正切

MySQL


>> 连接

mysql_connect(server,user,pwd,newlink,clientflag) - 连接

    mysql_pconnect(server,user,pwd,clientflag) - 长连接

    mysql_close(connection) - 关闭

>> 查询

mysql_select_db(database,connection) - 选择数据库

mysql_query(sql) - 执行查询,返回资源句柄

mysql_fetch_array(data,array_type) - 查询, 返回数组

    mysql_fetch_assoc(data) - 返回关联数组

mysql_fetch_object(data) - 查询, 返回对象

mysql_num_rows(data) -  结果行数

>> 连接状态

mysql_ping(connection) - 检查连接, 断开则重连

mysql_thread_id(connection) - 当前连接ID

mysql_client_encoding(connection) - 当前字符集

mysql_list_dbs(connection) - 列出数据库

>> 上次操作

mysql_info(connection) - 上次查询的信息

mysql_affected_rows(connection) - 影响行数

mysql_insert_id(connection) - 上次插入的ID

mysql_errno(connection) - 上次错误ID

    mysql_error(connection) - 上次错误信息

输入输出 I/O


>> 打印

print_r(value)

    var_dump(value) - 带类型

    var_export(value) - 返回合法的PHP代码

以上就介绍了[PHP]PHP函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南 适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南 Dec 24, 2024 pm 04:42 PM

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

我后悔之前不知道的 7 个 PHP 函数 我后悔之前不知道的 7 个 PHP 函数 Nov 13, 2024 am 09:42 AM

如果您是一位经验丰富的 PHP 开发人员,您可能会感觉您已经在那里并且已经完成了。您已经开发了大量的应用程序,调试了数百万行代码,并调整了一堆脚本来实现操作

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发 如何设置 Visual Studio Code (VS Code) 进行 PHP 开发 Dec 20, 2024 am 11:31 AM

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写

在PHP API中说明JSON Web令牌(JWT)及其用例。 在PHP API中说明JSON Web令牌(JWT)及其用例。 Apr 05, 2025 am 12:04 AM

JWT是一种基于JSON的开放标准,用于在各方之间安全地传输信息,主要用于身份验证和信息交换。1.JWT由Header、Payload和Signature三部分组成。2.JWT的工作原理包括生成JWT、验证JWT和解析Payload三个步骤。3.在PHP中使用JWT进行身份验证时,可以生成和验证JWT,并在高级用法中包含用户角色和权限信息。4.常见错误包括签名验证失败、令牌过期和Payload过大,调试技巧包括使用调试工具和日志记录。5.性能优化和最佳实践包括使用合适的签名算法、合理设置有效期、

php程序在字符串中计数元音 php程序在字符串中计数元音 Feb 07, 2025 pm 12:12 PM

字符串是由字符组成的序列,包括字母、数字和符号。本教程将学习如何使用不同的方法在PHP中计算给定字符串中元音的数量。英语中的元音是a、e、i、o、u,它们可以是大写或小写。 什么是元音? 元音是代表特定语音的字母字符。英语中共有五个元音,包括大写和小写: a, e, i, o, u 示例 1 输入:字符串 = "Tutorialspoint" 输出:6 解释 字符串 "Tutorialspoint" 中的元音是 u、o、i、a、o、i。总共有 6 个元

您如何在PHP中解析和处理HTML/XML? 您如何在PHP中解析和处理HTML/XML? Feb 07, 2025 am 11:57 AM

本教程演示了如何使用PHP有效地处理XML文档。 XML(可扩展的标记语言)是一种用于人类可读性和机器解析的多功能文本标记语言。它通常用于数据存储

解释PHP中的晚期静态绑定(静态::)。 解释PHP中的晚期静态绑定(静态::)。 Apr 03, 2025 am 12:04 AM

静态绑定(static::)在PHP中实现晚期静态绑定(LSB),允许在静态上下文中引用调用类而非定义类。1)解析过程在运行时进行,2)在继承关系中向上查找调用类,3)可能带来性能开销。

什么是PHP魔术方法(__ -construct,__destruct,__call,__get,__ set等)并提供用例? 什么是PHP魔术方法(__ -construct,__destruct,__call,__get,__ set等)并提供用例? Apr 03, 2025 am 12:03 AM

PHP的魔法方法有哪些?PHP的魔法方法包括:1.\_\_construct,用于初始化对象;2.\_\_destruct,用于清理资源;3.\_\_call,处理不存在的方法调用;4.\_\_get,实现动态属性访问;5.\_\_set,实现动态属性设置。这些方法在特定情况下自动调用,提升代码的灵活性和效率。

See all articles