现在的位置: 首页 > 综合 > 正文

输出中文字符

2018年04月14日 ⁄ 综合 ⁄ 共 644字 ⁄ 字号 评论关闭

输出中文字符

要想在图形中输出中文字符,需要对输出的中文字符进行编码。使用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);

?>

抱歉!评论已关闭.