收集整理常用php函数1
时间:2010-11-05 来源:大徐
1、计算文件单位大小函数
function cheksize($size) {
$size = floatval($size);
$rate_k = 1024 ;
$rate_m = 1024 * 1024;
$rate_g = 1024 * 1024 * 1024;
$new_size = $size / $rate_g;
if ($new_size < 1) {
$new_size = $size / $rate_m;
if ($new_size < 1) {
$new_size = round($size / $rate_k,2) . 'K';
if ($new_size == '0K') {
$new_size = "N/A";
}
} else
$new_size = round($new_size,2) . 'M';
} else
$new_size = round($new_size,2) . 'G';
return $new_size;
}
2、删除数组中的空元素,并且不会打乱数组内部序号
function array_remove_empty(&$arr, $trim = true){
foreach ($arr as $key => $value){
if (is_array($value)){
array_remove_empty($arr[$key]);
} else{
$value = trim($value);
if ($value == ''){
unset($arr[$key]);
} elseif ($trim){
$arr[$key] = $value;
}
}
}
}
3、检测客户端系统操作类型的函数
function sysinfo($agent){
$sys="";
if (stristr('win',$agent) && stristr('nt 5\.1',$agent)) {
$sys="Windows XP";
}elseif (stristr('win',$agent) && strstr('98',$agent)) {
$sys="Windows 98";
} elseif (stristr('win',$agent) && stristr('nt 5\.0',$agent)) {
$sys="Windows 2000";
} elseif (stristr('win 9x',$agent) && strpos($agent, '4.90')) {
$sys="Windows ME";
} elseif (stristr('win',$agent) && strpos($agent, '95')) {
$sys="Windows 95";
} elseif (stristr('win',$agent) && stristr('nt',$agent)) {
$sys="Windows NT";
} elseif (stristr('win',$agent) && strstr('32',$agent)) {
$sys="Windows 32";
} elseif (stristr('linux',$agent)) {
$sys="Linux";
} elseif (stristr('unix',$agent)) {
$sys="Unix";
} elseif (stristr('ibm',$agent) && stristr('os',$agent)) {
$sys="IBM OS/2";
} elseif (stristr('NetBSD',$agent)) {
$sys="NetBSD";
} elseif (stristr('BSD',$agent)) {
$sys="BSD";
} elseif (stristr('FreeBSD',$agent)) {
$sys="FreeBSD";
} else
$sys = "Unknown";
return $sys;
} 相关阅读 更多 +
排行榜 更多 +










