首頁  >  文章  >  後端開發  >  php這是一個隨機列印輸出字串的例子

php這是一個隨機列印輸出字串的例子

WBOY
WBOY原創
2016-07-29 09:16:21988瀏覽

<?<span>php
</span><span>header</span>("Content-type:text/html;charset='utf8'"<span>);
</span><span>error_reporting</span>(<span>E_ALL</span><span>);

</span><span>define</span>("CAPTCHA_LEN", 16); <span>//</span><span> 随机数长度</span><span>$captchaSource</span> = "0123456789abcdefghijklmnopqrstuvwxyz这是一个随机打印输出字符串的例子"; <span>//</span><span> 随机数字符源</span><span>$captchaResult</span> = ""; <span>//</span><span> 随机数返回值</span><span>$captchaSentry</span> = ""; <span>//</span><span> 随机数中间变量</span><span>for</span>(<span>$i</span>=0;<span>$i</span><CAPTCHA_LEN;<span>$i</span>++<span>){
    </span><span>$n</span> = <span>rand</span>(0, <span>strlen</span>(<span>$captchaSource</span><span>));
    </span><span>if</span>(<span>$n</span> >= 36<span>){
        </span><span>$n</span> = 36 + <span>ceil</span>((<span>$n</span> - 36) / 3) * 3<span>;
        </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 3<span>);
    }</span><span>else</span><span>{
        </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 1<span>);
    }
}

</span><span>echo</span> "随机打印输出字符串:".<span>$captchaResult</span>."<br>";

以上就介紹了php這是一個隨機列印輸出字串的例子,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn