首页 > Web开发 > 详细

php输出中文字符

时间:2017-03-01 12:25:05      阅读:206      评论:0      收藏:0      [点我收藏+]

中文字符不可以使用imagettftext()函数在图片中直接输出,如果要输出中文字符,需要先使用iconv()函数对中文字符进行编码,语法格式如下:
string iconv ( string $in_charset, string $out_charset, string $str )
说明:参数$in_charset是中文字符原来的字符集,$out_charset是编码后的字符集,$str是需要转换的中文字符串。函数最后返回编码后的字符串。这时使用imagettftext()函数就可以在图片中输出中文了。例如:
<?php
header("Content-type: image/gif");
$image=imagecreate(200, 200); //创建图形
$background=imagecolorallocate($image, 255, 255, 255); //背景色为白色
$red=imagecolorallocate($image, 0, 255, 0); //定义绿色
$text=‘南京2014青奥会‘; //初始化字符串
$font=‘C:\WINDOWS\Fonts\simhei.ttf‘; //字体文件,黑体
$codetext=iconv("UTF-8", "UTF-8", $text); //对中文进行编码
imagettftext($image, 20, 0, 10, 150, $red, $font, $codetext); //水平输出字符串$codetext
imagegif($image); //输出图形
imagedestroy($image);
?>

 

php输出中文字符

原文:http://www.cnblogs.com/feiyun8616/p/6483309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!