PHP常用函数整理

时间:2021-03-17 16:42:39
推荐网址:http://php.net/manual/zh/http://www.w3cschool.cc/php/php-ref-array.html


错误报告:
error_reporting(E_ALL);

字符串:
string addslashes ( string $str )
string stripslashes ( string $str )
string strip_tags ( string $str [, string $allowable_tags ] )
string trim ( string $str [, string $charlist = " \t\n\r\0\x0B" ] )
string ltrim ( string $str [, string $character_mask ] )
string rtrim ( string $str [, string $character_mask ] )
array explode ( string $delimiter , string $string [, int $limit ] )
array str_split ( string $string [, int $split_length = 1 ] )
string implode ( string $glue , array $pieces )或join()
echo()
string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )
string htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] )
string htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )
string md5 ( string $str [, bool $raw_output = false ] )
string sha1 ( string $str [, bool $raw_output = false ] )
string nl2br ( string $string [, bool $is_xhtml = true ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )
string substr ( string $string , int $start [, int $length ] )
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )或strchr; 如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分
string strrchr ( string $haystack , mixed $needle )
int strlen ( string $string )
string strrev ( string $string )
int strcmp ( string $str1 , string $str2 )
int strnatcmp ( string $str1 , string $str2 )
int strncmp ( string $str1 , string $str2 , int $len )
int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] )
mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )
string ucfirst ( string $str )
string ucwords ( string $str )
string str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]] )
string strtoupper ( string $string )
string strtolower ( string $string )
mixed highlight_string ( string $str [, bool $return = false ] )
string strtr ( string $str , string $from , string $to ) 例:strtr("Hilla Warld","ia","eo"); 把字符串中的字符 "ia" 替换为 "eo"
string str_repeat ( string $input , int $multiplier )
mixed sscanf ( string $str , string $format [, mixed &$... ] ) 例:sscanf('age:30 weight:60kg',"age:%d weight:%dkg",$age,$weight);int substr_compare ( string $main_str , string $str , int $offset [, int $length [, bool $case_insensitivity = false ]] )

正则表达式:
array preg_grep ( string $pattern , array $input [, int $flags = 0 ] )
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] )
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )
array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] )
int preg_last_error ( void )
string preg_quote ( string $str [, string $delimiter = NULL ] )

数组:
bool array_key_exists ( mixed $key , array $search )
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) 如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同 
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
array array_keys ( array $array [, mixed $search_value [, bool $strict = false ]] )
array array_merge ( array $array1 [, array $... ] )   
array array_pad ( array $input , int $pad_size , mixed $pad_value )  
mixed array_pop ( array &$array )  
int array_push ( array &$array , mixed $var [, mixed $... ] ) 
mixed array_shift ( array &$array ) 
int array_unshift ( array &$array , mixed $var [, mixed $... ] )
array array_values ( array $input )  
bool array_walk ( array &$array , callable $callback [, mixed $userdata = NULL ] )
array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] ) 
int count ( mixed $var [, int $mode = COUNT_NORMAL ] )或sizeof()
bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
bool rsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
bool asort ( array &$array [, int $sort_flags = SORT_REGULAR ] ) 
bool arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )  
bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] ) 
bool krsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )  
int extract ( array &$var_array [, int $extract_type = EXTR_OVERWRITE [, string $prefix = NULL ]] )
mixed max ( array $values )
mixed min ( array $values )
bool array_multisort ( array &$arr [, mixed $arg = SORT_ASC [, mixed $arg = SORT_REGULAR [, mixed $... ]]] )
array list ( mixed $varname [, mixed $... ] )
array array_combine ( array $keys , array $values )
array array_count_values ( array $input )
array array_diff ( array $array1 , array $array2 [, array $... ] )
array array_intersect ( array $array1 , array $array2 [, array $ ... ] )
array array_flip ( array $trans )
array array_map ( callable $callback , array $arr1 [, array $... ] )
array array_reverse ( array $array [, bool $preserve_keys = false ] )
bool shuffle ( array &$array )
mixed array_rand ( array $input [, int $num_req = 1 ] )
mixed end ( array &$array )
array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = false ]] )
array array_splice ( array &$input , int $offset [, int $length = 0 [, mixed $replacement ]] )
array array_chunk ( array $input , int $size [, bool $preserve_keys = false ] )
array array_column ( array $input , mixed $column_key [, mixed $index_key ] ) 返回array数组中键值为column_key的列
array array_change_key_case ( array $input [, int $case = CASE_LOWER ] )函数将数组的所有的键都转换为大写字母或小写字母
array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )
array array_fill ( int $start_index , int $num , mixed $value )

日期和时间:
string date ( string $format [, int $timestamp ] )
int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
int time ( void )
array getdate ([ int $timestamp = time() ] )
int strtotime ( string $time [, int $now = time() ] )

文件系统:

文件:
string realpath ( string $path )
string basename ( string $path [, string $suffix ] )
bool chmod ( string $filename , int $mode )
bool copy ( string $source , string $dest [, resource $context ] )
bool unlink ( string $filename [, resource $context ] )
string dirname ( string $path )
__FILE__;
float disk_total_space ( string $directory )
float disk_free_space ( string $directory )或diskfreespace();
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
bool fclose ( resource $handle )
int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
array file ( string $filename [, int $flags = 0 [, resource $context ]] )
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
string fread ( resource $handle , int $length )
string fgetc ( resource $handle )
string fgets ( resource $handle [, int $length ] )
string fgetss ( resource $handle [, int $length [, string $allowable_tags ]] )
int fwrite ( resource $handle , string $string [, int $length ] )
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
int fileatime ( string $filename )
int filectime ( string $filename )
int filemtime ( string $filename )
int filesize ( string $filename )
mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )
string filetype ( string $filename )
array stat ( string $filename )
bool is_readable ( string $filename )
bool is_writable ( string $filename )
bool is_executable ( string $filename )
bool is_dir ( string $filename )
bool is_file ( string $filename )
bool is_uploaded_file ( string $filename )
bool move_uploaded_file ( string $filename , string $destination )
bool flock ( resource $handle , int $operation [, int &$wouldblock ] )LOCK_SH取得共享锁定(读取的程序),LOCK_EX 取得独占锁定(写入的程序),LOCK_UN释放锁定

目录:
resource opendir ( string $path [, resource $context ] )
void closedir ([ resource $dir_handle ] )
array scandir ( string $directory [, int $sorting_order [, resource $context ]] )
string readdir ([ resource $dir_handle ] )
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )第三个参数true代表允许创建多级目录
bool rmdir ( string $dirname [, resource $context ] )
string getcwd ( void )
bool chdir ( string $directory )

图形图像:
array getimagesize ( string $filename [, array &$imageinfo ] )
resource imagecreate ( int $x_size , int $y_size )
resource imagecreatetruecolor ( int $width , int $height )
resource imagecreatefromjpeg ( string $filename )
bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
bool imagestring ( resource $image , int $font , int $x , int $y , string $s , int $col )
array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
bool imagesetpixel ( resource $image , int $x , int $y , int $color )
bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
bool imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style )
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

类:
bool class_exists ( string $class_name [, bool $autoload = true ] )
bool method_exists ( mixed $object , string $method_name )
mixed call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] )
mixed call_user_func_array ( callable $callback , array $param_arr )
ReflectionClass类

数学:
int rand ( int $min , int $max )
int mt_rand ( int $min , int $max )
float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )
mixed max ( mixed $value1 , mixed $value2 [, mixed $... ] )
mixed min ( mixed $value1 , mixed $value2 [, mixed $... ] )
number pow ( number $base , number $exp )
float ceil ( float $value )
float floor ( float $value )
string base_convert ( string $number , int $frombase , int $tobase )
string decbin ( int $number ) 十进制转二进制
string decoct ( int $number ) 十进制转八进制
string dechex ( int $number ) 十进制转十六进制
string bin2hex ( string $str ) 二进制转十六进制
number bindec ( string $binary_string ) 二进制转十进制
number octdec ( string $octal_string ) 八进制转十六进制
number hexdec ( string $hex_string ) 十六进制转十进制

mysql相关:
show tables like'';(检测是否存在某个表)
select version();获取mysql的型号信息)
mysql_list_fields();(获取一个表的字段)
mysql_fetch_field();(获取一个字段的信息)
mysql_num_rows();(总记录数)
mysql_insert_id();
mysql_free_result();
mysql_connect();
mysql_select_db();
mysql_query();
mysql_fetch_row();
mysql_fetch_array();
mysql_fetch_object();
from_unixtime把 unix时间戳转换为标准时间
unix_timestamp把标准时间转换为 unix时间戳//查询语句中不能使用strtotime()函数!但是可以使用unix_timestamp

系统:
memory_get_usage();
ini_set();
extension_loaded();
function_exists();

FTP:
ftp_connect($host,$port,$timeout);
ftp_close($hander);
ftp_login($hander,$username,$password);
ftp_put($hander,$remote,$local,$mode);
ftp_get($hander,$local,$remote,$mode);
ftp_mkdir($hander,$dirname);
ftp_rmdir($hander,$dirname);
ftp_delete($hander,$path);

json:
json_encode();
json_decode();


xml:
simplexml_import_dom();
simplexml_load_file();
simplexml_load_string();
SimpleXMLElement();

socket:
socket_create();
socket_connect();
socket_bind();
socket_listen();
socket_accept();
socket_read();
socket_write();
socket_close();

mail
mail($to,$subject,$message[,$additional_headers[,$additional_parameters]]);

其他:
function_exists();
exec(命令,数组,状态)
shell_exec(命令)
parse_url()
func_get_arg()、func_num_args()
filter_var() 函数通过指定的过滤器过滤变量 例:filter_var("someone@example....com", FILTER_VALIDATE_EMAIL)

常量:
PHP_OS
PHP_VERSION
PHP_SAPI
PHP_EOL(换行符)

缓存:
ob_start(); //打开一个输出缓冲区,所有的输出信息不再直接发送到浏览器,而是保存在输出缓冲区里面。
ob_clean(); //删除内部缓冲区的内容,不关闭缓冲区(不输出)。
ob_end_clean(); //删除内部缓冲区的内容,关闭缓冲区(不输出)。
ob_get_clean(); //返回内部缓冲区的内容,关闭缓冲区。相当于执行 ob_get_contents() and ob_end_clean()
ob_flush(); //发送内部缓冲区的内容到浏览器,删除缓冲区的内容,不关闭缓冲区。
ob_end_flush(); //发送内部缓冲区的内容到浏览器,删除缓冲区的内容,关闭缓冲区。
ob_get_flush(); //返回内部缓冲区的内容,并关闭缓冲区,再释放缓冲区的内容。相当于ob_end_flush()并返回缓冲区内容。
flush(); //将ob_flush释放出来的内容,以及不在PHP缓冲区中的内容,全部输出至浏览器;刷新内部缓冲区的内容,并输出。
ob_get_contents(); //返回缓冲区的内容,不输出。
ob_get_length(); //返回内部缓冲区的长度,如果缓冲区未被激活,该函数返回FALSE。
ob_get_level(); //Return the nesting level of the output buffering mechanism.
ob_get_status(); //Get status of output buffers.
ob_implicit_flush(); //打开或关闭绝对刷新,默认为关闭,打开后ob_implicit_flush(true),所谓绝对刷新,即当有输出语句(e.g: echo)被执行时,便把输出直接发送到浏览器,而不再需要调用flush()或等到脚本结束时才输出。
ob_gzhandler //ob_start回调函数,用gzip压缩缓冲区的内容。
ob_list_handlers //List all output handlers in use
output_add_rewrite_var //Add URL rewriter values
output_reset_rewrite_vars //Reset URL rewriter values
这些函数的行为受php_ini设置的影响:
output_buffering //该值为ON时,将在所有脚本中使用输出控制;若该值为一个数字,则代表缓冲区的最大字节限制,当缓存内容达到该上限时将会自动向浏览器输出当前的缓冲区里的内容。
output_handler //该选项可将脚本所有的输出,重定向到一个函数。例如,将 output_handler 设置为 mb_output_handler() 时,字符的编码将被修改为指定的编码。设置的任何处理函数,将自动的处理输出缓冲。
implicit_flush //作用同ob_implicit_flush,默认为Off。

密码相关:
password_hash(string $password,integer $algo[,array $options ])
password_verify(string $password,string $hash)
password_get_info(string $hash)
password_needs_rehash(string $hash,integer $algo[,array $options])

语法
  <?php ?>
  注释

数据类型
  整形
  字符串(对应函数)
  数组(对应函数)

运算符
  算数运算符
  字符串运算符
  赋值运算符
  位运算符
  逻辑运算符
  比较运算符
  错误控制@运算符
  三元运算符

流程控制
  条件判断
    if
    switch case
  循环
    break
    continue

函数

日期和时间

IO操作

图像处理

异常处理

面向对象

  封装

  继承

  多态

数据库

FTP

Socket