随机生成字符串-php-js

js
//随机获取字符

function randomString(len) {
  len = len || 32;
  var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  var maxPos = $chars.length;
  var pwd = '';
  for (i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}

var getCode = randomString(4);
 
  

  

 php
//随机获取字符
function getCode($length){ 

  $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
  $randStr = str_shuffle($str);//打乱字符串
  $key= substr($randStr,0,6);//substr(string,start,length);返回字符串的一部分
  return $key;

}

$str = getCode(4);
 
  

  

 
 

 随机生成字符串-php-js_第1张图片

你可能感兴趣的:(随机生成字符串-php-js)