PHP utf8 page verification code picture Chinese garbled_PHP tutorial

WBOY
Release: 2016-07-13 10:55:04
Original
1238 people have browsed it

During development, the Chinese verification code on the uft-8 page appeared garbled. I found the reason by searching on Baidu. There are solutions below for friends in need to refer to.

for($i=0;$i<4;$i++){ $rand.=dechex(rand(1,15));
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);

?>

Copy code

 代码如下 复制代码

$str=iconv("gbk","utf-8","新年快乐!");//确定要绘制的中文文字
imagettftext($im,12,3,20,20,$te,'msyhbd.ttf','中文en');

session_start();

代码如下 复制代码
$str=iconv("gbk","utf-8","新年快乐!");//确定要绘制的中文文字
imagettftext($im,12,3,20,20,$te,'msyhbd.ttf',$str);
//Generate random numbers
}

$_SESSION['checkpic']=$rand;

$im=imagecreatetruecolor(100,30);//Drawboard, create a new true color image//Set color $bg=imagecolorallocate($im,0,0,0);//Red, green, blue background color $te=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//Font color //Draw lines 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);//Coordinates (x1,y1) to coordinates (x2,y2) } //Draw dots
for($i=0;$i<200;$i++){

imagesetpixel($im,rand()%100,rand()%30,$te2);
}
<🎜> //Output Chinese <🎜> $str=iconv("gbk","utf-8","Happy New Year!");//Determine the Chinese text to be drawn<🎜> imagettftext($im,12,3,20,20,$te,'msyhbd.ttf','中文en');<🎜> <🎜>//Write the string in the upper left corner of the image<🎜> //imagestring($im,5,rand(0,50),rand(0,15),$rand,$te);<🎜> <🎜>//Output image<🎜> header("Content-type:image/jpeg");//File type<🎜> imagejpeg($im);<🎜> <🎜> <🎜> <🎜>?> Analysis of causes and solutions
The code is as follows Copy code
$str=iconv("gbk","utf-8","Happy New Year!");//Determine the Chinese text to be drawn imagettftext($im,12,3,20,20,$te,'msyhbd.ttf','中文en'); -->> It should be like this
The code is as follows Copy code
$str=iconv("gbk"," utf-8","Happy New Year!");//Determine the Chinese text to be drawn imagettftext($im,12,3,20,20,$te,'msyhbd.ttf',$str); http://www.bkjia.com/PHPjc/632267.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632267.htmlTechArticleDuring development, the Chinese verification code on the uft-8 page appeared garbled. I found the reason by searching on Baidu. There is a solution below. Friends who need the method can refer to it. The code is as follows Copy code ? sess...
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!