首页 > php教程 > php手册 > php这是一个随机打印输出字符串的例子,php打印输出字符串

php这是一个随机打印输出字符串的例子,php打印输出字符串

WBOY
发布: 2016-06-13 08:55:05
原创
1154 人浏览过

php这是一个随机打印输出字符串的例子,php打印输出字符串

<?<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.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板