PHP生成随机字符串的方法

WBOY
Release: 2016-06-20 13:05:16
Original
970 people have browsed it

PHP生成随机字符串的方法代码实现

< ?php<br />function genRandomString($len) <br />{ <br />    $chars = array( <br />        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",  <br />        "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",  <br />        "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",  <br />        "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",  <br />        "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",  <br />        "3", "4", "5", "6", "7", "8", "9" <br />    ); <br />    $charsLen = count($chars) - 1; <br /> <br />    shuffle($chars);    // 将数组打乱 <br />     <br />    $output = ""; <br />    for ($i=0; $i<$len; $i++) <br />    { <br />        $output .= $chars[mt_rand(0, $charsLen)]; <br />    } <br /> <br />    return $output; <br /> <br />} <br /> <br />$str = genRandomString(25); <br />$str .= "<br />"; <br />$str .= genRandomString(25); <br />$str .= "<br />"; <br />$str .= genRandomString(25); <br /> <br />echo $str; <br /> <br />?>
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!