PHP 经常使用的工具方法

1.php产生指定长度的字符串。 php

/**
 * @param $codeLen 随机字符串长度
 * @return string  随机字符串
 */
function randStr($codeLen){
    $str="abcdefghijkmnpqrstuvwxyz0123456789";
    $rand="";
    for($i=0; $i<$codeLen-1; $i++){
        $rand .= $str[mt_rand(0, strlen($str)-1)];  //如:随机数为30  则:$str[30]
    }
    return $rand;
}