Solution to garbled php verification code: First determine the Chinese verification code text to be drawn; then pass "imagettftext($im,12,3,20,20,$te,'msyhbd.ttf',$ str);" method can solve the problem of garbled characters.
Recommended: "PHP Video Tutorial"
php utf8 page verification code picture Chinese garbled code
During development, the Chinese verification code on the uft-8 page was garbled. I found the reason by searching on Baidu. Friends who need it can refer to the solution below. The code is as follows: ? session_start(); // Generate random numbers for ( $i =0; $i 4; $i ){ $rand .= dechex (rand(1,15));
The Chinese verification code on the uft-8 page appears garbled during development Yes, I found the reason by searching on Baidu. Friends who need it can refer to the solution below. The code is as follows:
<? session_start(); //生成随机数 for($i=0;$i<4;$i++){ $rand.=dechex(rand(1,15)); } $_SESSION['checkpic']=$rand; $im=imagecreatetruecolor(100,30);//画板,新建一个真彩色图像 //设置颜色 $bg=imagecolorallocate($im,0,0,0);//红,绿,蓝 背景颜色 $te=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//字体颜色 //画线条 for($i=0;$i<3;$i++){ $te2=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imageline($im,rand(0,100),0,rand(0,100),30,$te2);//坐标(x1,y1)到坐标(x2,y2) } //画点 for($i=0;$i<200;$i++){ imagesetpixel($im,rand()%100,rand()%30,$te2); } //输出中文 $str=iconv("gbk","utf-8","新年快乐!");//确定要绘制的中文文字 imagettftext($im,12,3,20,20,$te,'msyhbd.ttf','中文en'); //把字符串写在图像左上角 //imagestring($im,5,rand(0,50),rand(0,15),$rand,$te); //输出图像 header("Content-type:image/jpeg");//文件类型 imagejpeg($im); ?>
Analyze the cause and solution. The error code is as follows:
$str=iconv("gbk","utf-8","新年快乐!");//确定要绘制的中文文字 imagettftext($im,12,3,20,20,$te,'msyhbd.ttf','中文en');
Correct The code should look like this:
$str=iconv("gbk","utf-8","新年快乐!");//确定要绘制的中文文字 imagettftext($im,12,3,20,20,$te,'msyhbd.ttf',$str);
The above is the detailed content of What to do if the php verification code is garbled. For more information, please follow other related articles on the PHP Chinese website!