600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 输出中文字符

输出中文字符

时间:2022-05-13 15:21:38

相关推荐

输出中文字符

输出中文字符

要想在图形中输出中文字符,需要对输出的中文字符进行编码。使用iconv()函数,可以把一种编码的字符,转换为其他编码的字符。下面介绍在图形中输出中文字符的方法,

<?php

//创建一个新图形

$image = imagecreate(400,200);

//设置背景,分配颜色

$bgColor = imagecolorallocate($image,250,250,250);

$black = imagecolorallocate($image,0,0,0);

//指定imagettftext()函数使用的字体

$font = “simhei.ttf”;

//字义要输出的中文字符串

$string = “这是中文字符串”;

//对中文字符进行编码

$codeString = iconv(“GB2312″,”UTF-8″,$string);

//使用imagettftext()函数输出文字

imagettftext($image,20,0,30,30,$black,$font,$codeString);

imagettftext($image,20,180,200,100,$black,$font,$codeString);

imagettftext($image,20,60,200,180,$black,$font,$codeString);

//输出图形

header(“Content-type: image/png”);

imagepng($image);

//释放资源

imagedestroy($image);

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。