超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

PHP生成隨機(jī)字符串的技巧

時(shí)間:2025-11-04 10:00:54 php語(yǔ)言

PHP生成隨機(jī)字符串的技巧

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

  例子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);    /pic/p>

  $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";   /pic/p>

  $n = 8;   /pic/p>

  $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生成隨機(jī)字符串的技巧】相關(guān)文章:

PHP簡(jiǎn)單生成隨機(jī)字符串11-24

PHP生成自定義長(zhǎng)度隨機(jī)字符串實(shí)例11-14

php如何生成隨機(jī)密碼12-03

php怎么生成隨機(jī)密碼11-24

如何給php生成隨機(jī)密碼01-11

PHP生成隨機(jī)密碼的方法01-10

使用PHP批量生成隨機(jī)用戶名11-23

php生成隨機(jī)密碼的幾種方法09-17

php生成隨機(jī)密碼的4種方法02-28