我的漢字驗證碼,可以輸出,但是漢字顯示是亂碼,以下是我的圖和代碼,我的編碼格式utf-8,utf8,gb2312都試了
<?php
????? session_start();
????? $image=imagecreatetruecolor(200, 60);
????? $bgcolor=imagecolorallocate($image, 255, 255, 255);
????? imagefill($image, 0, 0, $bgcolor);
???? ?
????? $fontface='FZYTK.TTF'; //字體一定要命名為英文
?? ? ?
????? $str = "的一是在了不和有大這主中人上為們地個用工時要動國產(chǎn)以
?????????? 走議縣兵固除般引齒千勝細(xì)影濟白格效置推空配刀葉率述今選養(yǎng)德話";
????? //$strdb=array('慕' , '課' ,'網(wǎng)' ,'贊' );
????? $strdb=str_split($str,3);
????? //header('content-type:text/html; charset=gb2312');
????? //var_dump($strdb);
????? //die();
???? $captch_code='';
???? for($i=0;$i<4;$i++)//寫漢字????? ?
???? {
???????? $fontcolor=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));//字體顏色
?????? ?
???????? $index=rand(0,count($strdb));
???????? $cn=$strdb[$index];
???????? $captch_code.=$cn;
???????? imagettftext($image, mt_rand(20,24), mt_rand(-60,60),(40*$i+20), mt_rand(30,35),? $fontcolor, $fontface, $cn);
???????? //imagettftext(image, size, angle, x, y, color, fontfile, text)
?????? }
???? ?
????? $_SESSION['authcode']=$captch_code;
????? for ($i=0; $i < 200; $i++) //干擾點
????? {
???? ??? ?$pointcolor=imagecolorallocate($image, rand(50,200), rand(50,200), rand(50,200));
???? ??? ?imagesetpixel($image, rand(1,199), rand(1,59), $pointcolor);
????? }
???? ?
?????? for ($i=0; $i < 3; $i++) //干擾線
????? {
???? ??? ?$linecolor=imagecolorallocate($image, rand(80,220), rand(80,220), rand(80,220));
???? ??? ?imageline($image, rand(1,199), rand(1,59),rand(1,199), rand(1,59), $linecolor);
????? }
????? header('content-type: image/png; charset=gb2312');
????? imagepng($image);
????? imagedestroy($image);
???? ?
?>
2017-04-01
將 .php文件重新另存為 UTF-8 無BOM 的編碼格式,讓后就行了
2016-09-19
UTF-8 檔首無 BOM
2016-07-21
解決沒?我也出現(xiàn)了這個問題
2016-06-23
改成utf-8 無bom 就不會亂碼了
2016-05-29
應(yīng)該是你的驗證那個頁面的編碼格式?jīng)]有設(shè)置,或者設(shè)置的不是和utf-8的