| 
 最近流行彩字,下面是简单的实现方法: 一.彩字的简单实现  PHP程序员站--PHP程序员之家  
 
    
        www phperz com
            | 以下为引用的内容: header("content-type: image/png");
 $text = $_get['t'];
 $font = 'stxingka.ttf'; //ttf字体
 $fontsize = 30;
 $size = imagettfbbox($fontsize, 0, $font, $text); //获得字体长宽范围
 $dx = abs($size[2]-$size[0]) +10;
 $dy = abs($size[5]-$size[3]);
 //构建图像
 $im = imagecreate($dx,$dy);
 imagecolorallocate($im, 255,255, 255); //背景色
 $fontcolor = imagecolorallocate($im, 255, 0, 0); //字体颜色
 imagettftext($im, $fontsize, 0, 0, abs($size[5]), $fontcolor, $font, $text);
 imagepng($im);
 imagedestroy($im);
 |  上面的程序只是表述了一些彩字的基本原理,要实现更复杂和美观的彩字,所要做的只是更换一下字体,改一下字体颜色,添加一些背景图,再考虑一下缓存等,方法也差不多,朋友们可以自己试试.  www~phperz~.com
 二.彩字应用
 PHP程序员站--PHP程序员之家 上面的程序生成的彩字是通过"?t=文字"来传递的,但需注意的是,这些文字最好用urlencode来编码,当然,长度也应该有限制,这不是本文讨论的范围.
 另外,生成彩字的程序和传递文字的程序都使用utf-8编码,如果不是,手工转一下..
 要使用彩字,只需要用<img src="color.php?t=xxx" />即可,其中,color.php为生成彩字的程序(即上面的程序),xxx为经urlencode编码的文字(用来生成彩字)  PHP程序员站
 三.smarty插件  www.phperz.com  在smarty的plugins目录下新建一文件modifier.ubb.php,内容如下:   PHP程序员站--PHP程序员之家   www~phperz~.com  
 
    
        
            | 以下为引用的内容: function smarty_modifier_ubb($string){
 $ubb = array(
 '/\[b\](.+?)\[\/b\]/i', #加粗
 '/\[url=(.+?)\](.+?)\[\/url\]/i', #url
 '/\[colorfont\](.+?)\[\/colorfont\]/ie' #彩字,注意,要加e修饰符
 );
 $tohtml = array(
 '<b>\\1</b>',
 '<a href="\\1">\\2</a>',
         '"<img src=\'color.php?t=".urlencode("\\1")."\'/>"'  PHP程序员站 );
 //以上只是演ubb的实现,更多的ubb标签朋友们可以按方法自己实现,其中的color.php根椐实际去修改
 return preg_replace($ubb,$tohtml,$string);
 }   PHP程序员站
 |  
 这样,要显示彩字,只需在内容中加入
 [colorfont]文字[/colorfont]
 显示时,在smarty模板中使用ubb修饰符即可,如{$content|ubb}
 www phperz com 
 |