# 帝国cms网站标题关键词描述自动加密转换成乱码，前台显示正常，查看源码是乱码怎么办

*Published:* 2024-11-14
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2024年11月14日，已超过 180天没有更新



1、在e/class/userfun.php里添加自定义函数

```
error_reporting(E_ERROR); 
function unicode_encode($str){
    preg_match_all('/./u',$str,$matches);
    $unicodeStr = "";
    foreach($matches[0] as $m){
        //拼接
        $unicodeStr .= "&#".base_convert(bin2hex(iconv('UTF-8',"UCS-4",$m)),16,10).';';
    }
    $end = strrpos($unicodeStr, '#')+6;
    $unicodeStr = substr($unicodeStr, 0, $end);
    return $unicodeStr.';';
}
```

首页模板调用方式：

```
<title><?=unicode_encode($public_r[sitename])?></title>
[e:loop={'select siteintro,sitekey from [!db.pre!]enewspublic',1,24,0}]
<meta name="keywords" content="<?=unicode_encode($bqr[sitekey])?>" />
<meta name="description" content="<?=unicode_encode($bqr[siteintro])?>" />
```

列表页：

```
<?
$classid=$GLOBALS[navclassid];
$cinfo=$empire->fetch1("select classname,classpagekey,intro from {$dbtbpre}enewsclass where classid = $classid");
?>
<title><?=unicode_encode($cinfo[classname])?> - <?=unicode_encode($public_r[sitename])?></title>
<meta name="keywords" content="<?=unicode_encode($cinfo[classpagekey])?>" />
<meta name="description" content="<?=unicode_encode($cinfo[intro])?> " />
```

内容页：

```
<title><?=unicode_encode($navinfor[title])?> - <?=unicode_encode($public_r[sitename])?></title>
<meta name="keywords" content="<?=unicode_encode($navinfor[keyboard])?>" />
<meta name="description" content="<?=unicode_encode($navinfor[smalltext])?>" />
```