PHP学习之一晚撸下W3chscool

PHP 多维数组

其实简单的而言,多维数组就是由单个的数组组成的,两个数组嵌套组成一个二维数组,三个顾名思义就是三维数组。

先来一个简单的数组。

数字是key,引号里的是value

<?php 
$array = array('1' =>"咋" , '2' => "日" );
echo $array[2];
 ?>
输出:

然后再来几个有难度的,二维数组。

PHP Date() 函数

 /*
y:year
m:month
d:day
*/
语法:date(format,timestamp)     #参数一必选参数为时间戳,参数二为可选参数,规定时间戳,默认是当前的日期和时间。
<?php echo date("Y/m/d")."<br>"; echo date("Y.m.d")."<br>"; echo date("Y-m-d")."<br>"; echo date("m-d"); echo date("d-m");
echo "现在是".date("Y年m月d日");
?>
输出:
2016/11/11
2016.11.11
2016-11-11
现在是2016年11月11日

PHP Include 文件

如同英译那般,就是包含之意。

语法:
include 'filename';
或 require
'filename';
<?php include 'x.php';?>
<?php require 'noFileExists.php';?>

PHP 文件处理

readfile()函数,读取文件并且将文件输出到缓冲文件。

在根目录放一个1.txt,内容为:1

<?php
echo readfile('1.txt');
?>
输出:
1

 由此可见,不仅读取了1.txt这个文件并且还将其输出了。这就是readfile()函数的作用。

PHP 文件打开/读取/读取

文件的打开:fopen(filename,mode);
        参数一:打开的文件名
        参数二:打开的模式       #更多模式可至http://www.w3school.com.cn/php/php_file_open.asp
          案例:fopen("1.txt","r") or die("error");
文件的读取fread(name,length)
        参数1:要读取的文件
        参数2:读取的最大字节
          案例:fread($fopen,10);
          倘若取文本内所有数据的话,便是:fread($fopen,filesze("1.txt"));
文件的写入:fwrite(file,string)
        参数1:要写入的文件。
        参数2:要写入的字符串。           案例:$fopen=fopen("1.txt","w");              fwrite($fopen,"劝君珍惜少年时!");              fclose($fopen); 文件的关闭:fclose():自然就是关闭了。参数为要关闭的变量。
文件的单行读取:fgets(file);
        参数1:要读取的文件。
feof():函数检测是否已到达文件末尾
        

PHP 文件上传

 

原文地址:https://www.cnblogs.com/xishaonian/p/6034504.html