网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   PHP (https://www.0058.net/forumdisplay.php?f=75)
-   -   Php生成自定义长度随机字符串的函数分享 (https://www.0058.net/showthread.php?t=4925)

Paincourtville 2014-12-28 06:53 PM

Php生成自定义长度随机字符串的函数分享
 
这篇文章主要介绍了PHP生成自定义长度随机字符串的函数分享,需要的朋友可以参考下

php随机生成字符串可以自己定义自己所需要的长度,在实际应用开发中,经常遇到。


Code:

//随机生成字符串
function random($length) {
    srand(date("s"));
    $possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $string = "";
    while(strlen($string)<$length) {
          $string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
    }
    return($string);
}



All times are GMT +8. The time now is 02:00 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.