Discuz 3.4 Emoji
[*]編輯「discuz_database.php」,路徑「/source/class/discuz/discuz_database.php」。
[*]增加程式碼,約358行後方
public static function utf8mb4($m = ''){
$m = preg_split('/(?<!^)(?!$)/u', $m);
foreach ($m as $k => $z) {
if(strlen($z)>3){
$z = unpack('H*', mb_convert_encoding($z,'UTF-32','UTF-8'));
$m[$k] = '&#x' . preg_replace('/^0*/','',$z) . ';';
}
}
return implode('',$m);
}
public static function mb4utf8($m = ''){
if (is_string($m)){
preg_match_all('/&#x({4,5});/',$m,$p);
foreach ($p as $k => $h) {
$p[$k] = mb_convert_encoding( pack('H*', str_pad($h, 8, '0', STR_PAD_LEFT) ) ,'UTF-8','UTF-32');
}
return str_replace($p,$p,$m);
}elseif(is_array($m)){
foreach ($m as &$v) {
$v = self::mb4utf8($v);
}
}
return $m;
}
[*]在public static function fetch($resourceid, $type = MYSQL_ASSOC) {刪除return self::$db->fetch_array($resourceid, $type);
新增return self::mb4utf8(self::$db->fetch_array($resourceid, $type));
[*]於
public static function fetch_first($sql, $arg = array(), $silent = false) {刪除$ret = self::$db->fetch_array($res);
新增$ret = self::mb4utf8(self::$db->fetch_array($res));
[*]於
public static function fetch_all($sql, $arg = array(), $keyfield = '', $silent=false) {刪除while ($row = self::$db->fetch_array($query)) {
新增while ($row = self::mb4utf8(self::$db->fetch_array($query))) {
[*]於
public static function result($resourceid, $row = 0) {刪除return self::$db->result($resourceid, $row);
新增return self::mb4utf8(self::$db->result($resourceid, $row));
[*]於
public static function quote($str, $noarray = false) {新增$str = self::utf8mb4($str);
[*]編輯「function_core.php」,路徑「/source/function/function_core.php」。
[*]於
function dhtmlspecialchars($string, $flags = null)刪除$string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
新增$string = preg_replace('/&((#(\d{3,6}|x{4,5}));)/', '&\\1', $string);
[*]完成。
頁:
[1]