Home >Backend Development >PHP Tutorial >php中文验证码实现示例分享_PHP

php中文验证码实现示例分享_PHP

WBOY
WBOYOriginal
2016-06-01 11:57:29853browse

复制代码 代码如下:
 $text = '的一是不了能好都然没日于起还发成事只作当想看文无开手十用主行方又如前所本见经头面公同三已老从动两长知民样现分将外但身些与高意进把法此实回二理美点月明其种声全工己话儿者向情部正名定女问力机给等几很业最间新什打便位因重被走电四第门相次东政海口使教西再平真听世气信北少关并内加化由却代军产入先山五太水万市眼体别处总才场师书比住员九笑性通目华报立马命张活难神数件安表原车白应路期叫死常提感金何更反合放做系计或司利受光王果亲界及今京务制解各任至清物台象记边共风战干接它许八特觉望直服毛林题建南度统色字请交爱让';
 $im = imagecreatetruecolor(100,45);
 $font = './msyhbd.ttf';
 $len = mb_strlen($text,'UTF-8');
 $grey = imagecolorallocate($im,200,200,200);
 imagefill($im,0,0,$grey);
 for($i = 0,$x = 0 ;$i   $color = imagecolorallocate($im,mt_rand(0,190),mt_rand(0,190),mt_rand(0,190));
  $x += $i*10 + mt_rand(1,5);
  $tmp = mb_substr($text,mt_rand(0,$len),1,'UTF-8');
  imagettftext($im,mt_rand(10,16),mt_rand(-15,15),$x,mt_rand(21,25),$color,$font,$tmp);
 }
 header('content-type:image/png');
 imagepng($im);
 imagedestroy($im); 
?>

Statement:
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