Home > php教程 > php手册 > PHP random characters

PHP random characters

WBOY
Release: 2016-10-17 09:12:04
Original
1247 people have browsed it

随机字符生成
function randStr($length=4,$type="1"){<br>         $array = array(<br>             '1' => '0123456789',<br>             '2' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',<br>             '3' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',<br>         );<br>         $string = $array[$type];<br>         $count = strlen($string)-1;<br>         $rand = '';<br>         for ($i = 0; $i < $length; $i++) {<br>             $rand .= $string[mt_rand(0, $count)];<br>         }<br>         return $rand;<br>     }

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template