8条使用频率较高的PHP函数 01 December 2009 0:55 Tuesday by 小屋 浏览(1386)

1.产生随机字符串函数

function random($length) {
$hash = @#@#;
$chars = @#ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz@#;
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}

2.截取一定长度的字符串

注:该函数对GB2312使用有效

function wordscut($string, $length ,$sss=0) {
if(strlen($string) > $length) {
               if($sss){
                      $length=$length - 3;
                      $addstr=@# ...@#;
                }
for($i = 0; $i < $length; $i++) {
   if(ord($string[$i]) > 127) {

阅读全文>>