<?<span php </span><span //</span><span 随机产生六位数密码Begin</span> <span function</span> randStr(<span $len</span>=6,<span $format</span>='ALL'<span ) { </span><span switch</span>(<span $format</span><span ) { </span><span case</span> 'ALL': <span $chars</span>='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'; <span break</span><span ; </span><span case</span> 'CHAR': <span $chars</span>='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-@#~'; <span break</span><span ; </span><span case</span> 'NUMBER': <span $chars</span>='0123456789'; <span break</span><span ; </span><span default</span> : <span $chars</span>='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~'<span ; </span><span break</span><span ; } www.jbxue.com </span><span mt_srand</span>((<span double</span>)<span microtime</span>()*1000000*<span getmypid</span><span ()); </span><span $password</span>=""<span ; </span><span while</span>(<span strlen</span>(<span $password</span>)<<span $len</span><span ) </span><span $password</span>.=<span substr</span>(<span $chars</span>,(<span mt_rand</span>()%<span strlen</span>(<span $chars</span>)),1<span ); </span><span return</span> <span $password</span><span ; } </span><span //</span><span 随机产生六位数密码End</span> ?>
Script Academy has provided you with a lot of articles about php generating random passwords or random numbers. Friends who are interested can read the following articles: