1
/**2
* 截取中英混合字符给长度,不足用
补足3
*4
* @param string $str25
* @param int $length6
* @param char $point7
* @return string String8
*/9
function subString($str2,$length,$point='')10
{11
$str2 = trim($str2);12
$sLen = strlen($str2); //中英混合字符编码长度13
$n1 = 0;14
$n2 = 0;15
$p = '.';16
for($i=0;$i<$sLen;$i++)17
{18
if(ord($str2[$i])>128) $n1++;19
}20
$strLength = $sLen - $n1/2; //中英混合字符表面长度21
22
if(!empty($str2))23
{24
if($strLength > $length)25
{26
for($i=0;$i<$sLen;$i++)27
{28
if(ord($str2[$i])>128) $n2++;29
if($n2%2 == 0)30
{31
if(($i-$n2/2)== $length)32
$cutLen = $i;33
}34
}35
$subs = substr($str2,0,$cutLen);36
}37
else38
{ 39
for($j = 0;$j < ($length-$strLength); $j++)40
{41
$point .= $p;42

43
}44
$subs = $str2.$point;45
}46
return $subs;47
}48
else49
{50
return -1;51
}52
}53
$str2 = "abc利de坚on合众国白宫克林顿";54
echo subString($str2,17);1
/** 计算文件夹大小2
* $pathString:文件夹路径3
* $floderSize:文件夹大小4
* $separator:分隔符5
*/6
function ifDir($pathString,&$floderSize=0,$separator='/')7
{8

9
if(is_dir($pathString))10
{11
if($handle = opendir($pathString))12
{13
while(($file = readdir($handle))!==false)14
{15
if($file != '.'&&$file != '..')16
{17
$psf = $pathString.$separator.$file;18
if(is_dir($psf ))19
ifDir($psf,$floderSize); //递归调20
else21
{22
$floderSize += filesize($psf);23
}24
}25
}26
}27
return ($floderSize);28
}29
else30
return -1;31

32
}33

34
//e.g35
$path = "/usr/local/code";36
//$path = "sdf";37
if(ifDir($path)!= -1)38
{39
$floderSize = ifDir($path)/1024;40
echo $floderSize;41
}42
else43
echo "路径有误!";
浙公网安备 33010602011771号