您的位置:首页 > 其它

输出中文字符

2010-12-03 13:24 295 查看
输出中文字符

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

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: