ホームページ >バックエンド開発 >PHPチュートリアル >PHPのランダム文字列生成関数

PHPのランダム文字列生成関数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2016-07-25 08:51:211070ブラウズ
  1. functionrandom_string($length, $max=FALSE)
  2. {
  3. if (is_int($max) && $max > $length)
  4. {
  5. $length = mt_rand($length, $max);
  6. }
  7. $output = '';
  8. for ($i=0; $i<$length; $i++)
  9. {
  10. $that = mt_rand(0,2);
  11. if ($that === 0)
  12. {
  13. $output .= mt_rand(0,9);
  14. }
  15. elseif ($that === 1)
  16. {
  17. $output .= chr(mt_rand(65,90));
  18. }
  19. else
  20. {
  21. $output .= chr(mt_rand(97,122));
  22. }
  23. }
  24. return $output;
  25. }
复制發


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。