PHP常用函数总结(180多个)

2019-05-02 07:19:53于丽

 if(is_uploaded_file($_FILES['bus']['tmp_name'])){
 if( move_uploaded_file($_FILES['bus']['tmp_name'],
 $NewPath) ){
 echo '上传成功<br /><img src="'.$NewPath.'">';
 }else{
 exit('失败');
 }
 }else{
 exit('不是上传文件');
 }

调用: bool move_uploaded_file ( string $filename , string

时间函数

155.time(): 返回当前的 Unix 时间戳time(); 调用: int time ( void ) 输出: 返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数

156.mktime(): 取得一个日期的 Unix 时间戳

    mktime(0, 0, 0, 4, 25, 2012);
调用: int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] )   156.date(): 格式化一个本地时间/日期

date('Y年m月d日 H:i:s');
调用: string date ( string $format [, int $timestamp ] )

输出: 2016年09月10日 20:45:54

157.checkdate(): 验证一个格里高里日期 调用: bool checkdate ( int $month , int $day , int $year) 输出: 如果给出的日期有效则返回 TRUE,否则返回 FALSE

 if(checkdate(6,31,2012)){
 echo '成立';
 }else{
 echo '不成立';
 }

158.date_default_timezone_set(): 设定用于一个脚本中所有日期时间函数的默认时区

    date_default_timezone_set('PRC');
调用: bool date_default_timezone_set ( string $timezone_identifier)

返回值: 如果 timezone_identifier 参数无效则返回 FALSE,否则返回 TRUE。

159.getdate(): 取得日期/时间信息 调用: array getdate ([ int $timestamp ] )

输出: 返回一个根据timestamp得出的包含有日期信息的关联数组。如果没有给出时间戳则认为是当前本地时间

 $t=getdate();
 var_dump($t);

160.strtotime(): 将任何英文文本的日期时间描述解析为 Unix 时间戳

 echo strtotime("now");
 int strtotime ( string $time [, int $now ] )  
 echo strtotime("10 September 2000");
 echo strtotime("+1 day");
 echo strtotime("+1 week");
 echo strtotime("+1 week 2 days 4 hours 2 seconds");
 echo strtotime("next Thursday");
 echo strtotime("last Monday");

161.microtime(): 返回当前 Unix 时间戳和微秒数 调用: mixed microtime ([ bool $get_as_float ] )

 $start=microtime(true);
 sleep(3);
 $stop=microtime(true);
 echo $stop-$start;

其他常用:

162.intval(): 获取变量的整数值 调用: int intval ( mixed $var [, int $base = 10 ] ) 通过使用指定的进制 base 转换(默认是十进制),返回变量 var 的 integer 数值。 intval() 不能用于 object,否则会产生 E_NOTICE 错误并返回 1。

var: 要转换成 integer 的数量值

base: 转化所使用的进制

返回值: 成功时返回 var 的 integer 值,失败时返回 0。 空的 array 返回 0,非空的 array 返回 1。

相关文章 大家在看