输出中文字符
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);
?>
要想在图形中输出中文字符,需要对输出的中文字符进行编码。使用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);
?>
相关文章推荐
- cmd chcp命令切换字符格式 cmd重定向输出到文件出现中文乱码的处理方法
- opencv输出中文字符,并控制字符大小
- Windows 控制台(console)输出宽字符(解决中文输出乱码问题)
- notepad++ java编码,输出中文字符时,编译出错
- OSX下MyEclipse10里Tomcat控制台输出中文字符乱码问题
- OSX下MyEclipse10里Tomcat控制台输出中文字符乱码问题
- C++输出中文字符 C/C++多字节字符与宽字符的输出
- 解决 iOS NSDictionary 输出中文字符”乱码”(Unicode编码)问题
- C++输出中文字符
- 中文字符存入list中输出为乱码
- 向控制台输出unicode中文字符
- OS NSDictionary 输出中文字符”乱码”(Unicode编码)问题?
- 输出中文字符输出了乱码
- Cocos2d-x VS2010 win32 输出中文字符的方法
- Python如何输出包含在对象中的中文字符?
- C++输出中文字符
- 允许Python文档中显示中文 & 允许SublimeText2输入中文 & 允许Python输出unicode字符
- _tprintf(_T("PDF转换成功\n")); 无法输出中文字符
- OSX下MyEclipse10里Tomcat控制台输出中文字符乱码问题
- 在文本文件中输出宽中文字符