二十一段救命的PHP代码

 1. PHP可阅读随机字符串

  此代码将创建一个可阅读的字符串,使其更接近词典中的单词,实用且具有密码验证功能。

/************** 
*@length - length of random string (must be a multiple of 2)

 **************/ 

function readable_random_string($length = 6){     
$conso=array("b","c","d","f","g","h","j","k","l",     "m","n","p","r","s","t","v","w","x","y","z");     
$vocal=array("a","e","i","o","u");     
   $password="";    
    srand ((double)microtime()*1000000);    
    $max = $length/2;     
for($i=1; $i<=$max; $i++)     {     
    $password.=$conso[rand(0,19)];     
    $password.=$vocal[rand(0,4)];     
}     
    return $password; 
}  

  2. PHP生成一个随机字符串

  如果不需要可阅读的字符串,使用此函数替代,即可创建一个随机字符串,作为用户的随机密码等。

/************* *
@l - length of random string */ 
function generate_rand($l){      $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";  
 srand((double)microtime()*1000000);  
 for($i=0; $i<$l; $i++) {      
 $rand.= $c[rand()%strlen($c)];   
}  
 return $rand;
 } 

  

转载于:https://www.cnblogs.com/freespider/archive/2011/10/25/2224500.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值