吐槽一下: php 的
函数命名风格不统一!!!
字符串函数
explode(',', $str); //切字符串,返回数组
implode("-", $array); //拼接数组元素,返回字符串
trim($str) //去除两边空白字符
ltrim($str) //去除左边空白字符
rtrim($str) //去除右边空白字符
str_replace(search, replace, subject); //查找替换
preg_match(patter, subject, &$array) // 正则匹配替换
preg_match_all(patter, subject, &$array) //同上, 结果$array为多维数组
strchr($string, $needle); //查找第一次出现的字符,返回出现字符后的字符串
strrchr() //同上, 最后一次出现
strpos() //同上, 返回index数
stripos() //同上, 不区分大小写
sub_str($str, start_number, end_number) //截取字符串
数组函数
count($array) //计算数组大小
array_push($array, $value) //数组右侧压栈
array_pop($array) //数组右侧出栈
array_unshift($array, $value); // 左侧压入数据
array_shift($array) //左侧数据出栈
文件函数
fileatime("/path/to/file_name");
filectime("/path/to/file_name");
fileamtime("/path/to/file_name");
filesize("/path/to/file_name");
filetype("/path/to/file_name");
file_exists("/path/to/file_name");
file_get_content("/path/to/file_name");
file_put_content("/path/to/file_name", $content, FILE_APPEND);
COPY("SOURCE_PATH/XX.file", "DESC_PATH/XX.file");
$fp = fopen("/path/to/file_name"); /r, w, a, +, x
fread($fp, $length);
fgets($fp);
fgetc($fp);
feof($fp);
unlink("/path/to/file_name");
ftell($fp); fseek(); SEEK_CUR SEEK_END SEEK_SET
flock($fp, LOCK_SH); LOCK_SH LOCK_EX LOCK_UN LOCK_EX | LOCK_NB
fclose($fp);
目录操作
is_dir();
mkdir('dirname', 0755, true);
rmdir();
opendir();
readdir();
closedir();
rename();
unset();
scandir("/path/");
HTTP头函数
//header函数
header("content-type:text/html; charset=utf-8");
header("content-length:$length");
header("Refresh:2; URL=http://localhost//session.php");
header("Location:http://localhost//session.php");
header("content-disposition:attachment; filename=xxx.zip");
header("content-type:$mime");
header("content-length:$filesize");
SESSION函数
session_start();
$_SESSION;
session_destroy();
session_set_cookie_params(time() + 60, '/', '.me.com', false, true);
session_set_save_handler('open', 'close', 'read', 'write', 'del', 'gc');