discuz! X3.4特殊字符乱码解决方案!
Discuz! X3.4升级后,帖子内容使用Unicode编码会出现直接显示源码问题

打开:source\function\function_core.php
$string = str_replace(array(‘&’, ‘”‘, ‘<‘, ‘>’), array(‘&’, ‘”‘, ‘<‘, ‘>’), $string);
下面加入
if(strpos($string, ‘&#’) !== false) {
$string = preg_replace(‘/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/’, ‘&\\1’, $string);
}
根据提供的参考内容,以下是解决Discuz!论坛网站特殊字符乱码的代码:
打开文件:source\function\function_core.php
在文件底部加入以下代码:
“`php
<?php
function discuzcode($text) {
$text = str_replace(array(‘&’, ‘<‘, ‘>’, ‘ ‘), array(‘&’, ‘<‘, ‘>’, ‘ ‘), $text);
if (strpos($text, ‘&#’) !== false) {
$text = preg_replace(‘/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/’, ‘&\\1’, $text);
}
return $text;
}
?>
“`
然后在需要显示特殊字符的地方,使用`discuzcode()`函数对特殊字符进行处理。例如:
“`html
<?php echo discuzcode(“特殊字符:❤️🌟💖”); ?>
“`
这样就可以解决Discuz!论坛网站特殊字符乱码的问题了。
保存文件 更新缓存 刷新帖子 看看效果