Home > Backend Development > PHP Tutorial > php This is an example of randomly printing out a string, php printing out a string_PHP tutorial

php This is an example of randomly printing out a string, php printing out a string_PHP tutorial

WBOY
Release: 2016-07-13 09:44:02
Original
916 people have browsed it

php This is an example of randomly printing out a string, php printing out a string

<?<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>";
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1051218.htmlTechArticlephp This is an example of randomly printing out a string, php printing out a string? php header ("Content- type:text/html;charset='utf8'" ); error_reporting ( E_ALL ); define ("CAPTCHA_...
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