php 基础复习 2018-06-19

(1)date()函数

如果从代码返回的不是正确的时间,有可能是因为您的服务器位于其他国家或者被设置为不同时区。

因此,如果您需要基于具体位置的准确时间,您可以设置要用的时区。

date_default_timezone_set("Asia/Shanghai");
echo "当前时间是 " . date("h:i:sa");

date()函数第二个参数的时间戳可以不传递,表示当前的时间戳。

(2)mktime() 函数

返回日期的 Unix 时间戳。Unix 时间戳包含 Unix 纪元(1970 年 1 月 1 日 00:00:00 GMT)与指定时间之间的秒数。

mktime(hour,minute,second,month,day,year)
$d=mktime(9, 12, 31, 6, 10, 2015);
echo "创建日期是 " . date("Y-m-d h:i:sa", $d);

(3)PHP strtotime() 函数

用于把人类可读的字符串转换为 Unix 时间,语法:strtotime(time,now)

$d=strtotime("tomorrow");
echo date("Y-m-d h:i:sa", $d) . "<br>";//获取明天的当前时间
//使用第二个参数
$d=strtotime("tomorrow",time()-86400);
echo date("Y-m-d h:i:sa", $d) . "<br>";

(4)PHP include 和 require 语句

通过 include 或 require 语句,可以将 PHP 文件的内容插入另一个 PHP 文件(在服务器执行它之前)。

include 和 require 语句是相同的,除了错误处理方面:

  • require 会生成致命错误(E_COMPILE_ERROR)并停止脚本
  • include 只生成警告(E_WARNING),并且脚本会继续

(5)常见语言的全称:

AJAX = Asynchronous JavaScript and XML
CSS = Cascading Style Sheets
HTML = Hyper Text Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language

(6)PHP读取文本内容:

//方式一、readfile函数读取内容并返回字节数
echo readfile("webdictionary.txt");
echo '<br/>';

//方式二、file_get_contents,不传递后几个参数默认获取全部内容
echo file_get_contents("webdictionary.txt");
echo '<br/>';

//方式三、fgets,获取一行内容
$fp = fopen("webdictionary.txt",'r');
while(!feof($fp)){
    echo fgets($fp);
    echo '<br/>';
}
fclose($fp);

//方式四、fread() 读取文件,格式fread(file,length),两个参数都必传
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);

echo '<br/>';

//方式五、fgetc() 从文件中读取单个字符,格式fread(file,length),两个参数都必传
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
// 输出单字符直到 end-of-file
while(!feof($myfile)) {
  echo fgetc($myfile);
}
fclose($myfile);

//方式六、file() 整个文件读入一个数组中
$fileArr = file("webdictionary.txt");
var_dump($fileArr);

(7)php文件上传的后缀判断

对于 IE,识别 jpg 文件的类型是 pjpeg,对于 FireFox,是 jpeg。

 

猜你喜欢

转载自www.cnblogs.com/gyfluck/p/9198850.html
今日推荐