php這是一個隨機打印輸出字符串的例子,php打印輸出字符串
<?php
header("Content-type:text/html;charset='utf8'");
error_reporting(E_ALL);
define("CAPTCHA_LEN", 16); // 隨機數長度
$captchaSource = "0123456789abcdefghijklmnopqrstuvwxyz這是一個隨機打印輸出字符串的例子"; // 隨機數字符源
$captchaResult = ""; // 隨機數返回值
$captchaSentry = ""; // 隨機數中間變量
for($i=0;$i<CAPTCHA_LEN;$i++){
$n = rand(0, strlen($captchaSource));
if($n >= 36){
$n = 36 + ceil(($n - 36) / 3) * 3;
$captchaResult .= substr($captchaSource, $n, 3);
}else{
$captchaResult .= substr($captchaSource, $n, 1);
}
}
echo "隨機打印輸出字符串:".$captchaResult."<br>";