zoukankan      html  css  js  c++  java
  • php输出中文字符

    中文字符不可以使用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:WINDOWSFontssimhei.ttf'; //字体文件,黑体
    $codetext=iconv("UTF-8", "UTF-8", $text); //对中文进行编码
    imagettftext($image, 20, 0, 10, 150, $red, $font, $codetext); //水平输出字符串$codetext
    imagegif($image); //输出图形
    imagedestroy($image);
    ?>

  • 相关阅读:
    树状数组和线段树
    N皇后问题(函数式编程与过程式)
    单例模式
    BitSet
    蓄水池抽样问题
    关于动态规划的一些感想
    53最大子序和
    5最长回文子串
    139单词拆分
    91.解码方法
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/6483309.html
Copyright © 2011-2022 走看看