av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

php語言

PHP生成隨機字符串的技巧

時間:2024-12-29 23:54:28 php語言 我要投稿
  • 相關(guān)推薦

PHP生成隨機字符串的技巧

  使用PHP開發(fā)應(yīng)用程序,尤其是網(wǎng)站程序,常常需要生成隨機密碼,而本文收集整理了幾種生成隨機字符串的方法,希望對您有所幫助。

  例子1:

  復(fù)制代碼 代碼如下:

  < ?php

  function genRandomString($len)

  {

  $chars = array(

  "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",

  "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",

  "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",

  "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",

  "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",

  "3", "4", "5", "6", "7", "8", "9"

  );

  $charsLen = count($chars) - 1;

  shuffle($chars);    // 將數(shù)組打亂

  $output = "";

  for ($i=0; $i<$len; $i++)

  {

  $output .= $chars[mt_rand(0, $charsLen)];

  }

  return $output;

  }

  $str = genRandomString(25);

  $str .= "<br />";

  $str .= genRandomString(25);

  $str .= "<br />";

  $str .= genRandomString(25);

  echo $str;

  ?>

  例子2:

  復(fù)制代碼 代碼如下:

  <?php

  /* Generate Password

  * Length : 8

  */

  $str = "0123456789abcdefghijklmnopqrstuvwxyz";   //   輸出字符集

  $n = 8;   //   輸出串長度

  $len = strlen($str)-1;

  for($j=0 ; $j<200 ; $j++){

  for($i=0 ; $i<$n; $i++){

  $s .=  $str[rand(0,$len)];

  }

  echo $s . "<br/>";

  $s = "";

  }

  ?>

【PHP生成隨機字符串的技巧】相關(guān)文章:

PHP簡單生成隨機字符串10-30

PHP生成自定義長度隨機字符串實例07-22

php如何生成隨機密碼07-01

PHP生成隨機密碼的方法11-06

php怎么生成隨機密碼10-29

如何給php生成隨機密碼09-09

使用PHP批量生成隨機用戶名10-17

php生成隨機密碼的幾種方法07-11

php生成N個不重復(fù)的隨機數(shù)07-27