rmdir() 函数删除空的目录。
例
rmdir() 函数删除空的目录。
例
$uAgent = $_SERVER['HTTP_USER_AGENT'];
$osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Window|ubuntu|Longhorn|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS/2|OSF1|SUN";
例
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
我们常见一些网站在做ajax时返回JSON格式的数据:
<?php
//获取文件夹大小
function dir_size($dir) {
if (!preg_match('#/$#', $dir)) {
$dir .= '/';
}
$totalsize = 0;
//调用文件列表
foreach (get_file_list($dir) as $name) {
$totalsize += (@is_dir($dir.$name) ? dir_size("$dir$name/") :
(int)@filesize($dir.$name));
}
return $totalsize;
}
//获取文件列表
function get_file_list($path) {
$f = $d = array();
//获取所有文件
foreach (get_all_files($path) as $name) {
if (@is_dir($path.$name)) {
$d[] = $name;
} else if (@is_file($path.$name)) {
$f[] = $name;
}
}
natcasesort($d);
natcasesort($f);
return array_merge($d, $f);
}
//获取所有文件
function get_all_files($path) {
$list = array();
if (($hndl = @opendir($path)) === false) {
return $list;
}
while (($file=readdir($hndl)) !== false) {
if ($file != '.' && $file != '..') {
$list[] = $file;
}
}
closedir($hndl);
return $list;
}
//转换单位
function setupSize($fileSize) {
$size = sprintf("%u", $fileSize);
if($size == 0) {
return("0 Bytes");
}
$sizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizename[$i];
}
//目录
$path = './test_dir/';
//显示文件列表
print_r(get_file_list($path)).'<br>';
//显示文件大小
echo dir_size($path).'<br>';
//显示转换过单位的大小
echo setupSize(dir_size($path));
?>
此函数用于截取gb2312编码的中文字符串:
<?php
// 说明:截取中文字符串
function mysubstr($str, $start, $len) {
$tmpstr = "";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}
?>
用PHP调用Linux的命令行 ,执行压缩命令,OK,马上行动!
/*拆分成3个txt文件 分别是wow_1.txt wow_2.txt 和 wow_3.txt 全部放到 Exl_file 目录下*/
默认情况下,PHP 指令 magic_quotes_gpc 为 on,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。
二维数组