1<?php 2/** 3 * SquirrelMail GB18030 decoding functions 4 * 5 * This file contains gb18030 decoding function that is needed to read 6 * gb18030 encoded mails in non-gb18030 locale. 7 * 8 * @copyright (c) 2005 The SquirrelMail Project Team 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 10 * @version $Id: gb18030.php 12467 2007-06-25 15:52:44Z kink $ 11 * @package decode 12 * @subpackage eastasia 13 */ 14 15/** 16 * Decode gb18030 encoded string 17 * @param string $string gb18030 string 18 * @param boolean $save_html don't html encode special characters if true 19 * @return string $string decoded string 20 */ 21function charset_decode_gb18030 ($string, $save_html=false) { 22 // global $aggressive_decoding; 23 24 // don't do decoding when there are no 8bit symbols 25 if (! sq_is8bit($string,'gb18030')) 26 return $string; 27 28 // this is CPU intensive task. Use recode functions if they are available. 29 if (function_exists('recode_string')) { 30 // if string is already sanitized, undo htmlspecial chars 31 if (! $save_html) { 32 $string=str_replace(array('"','<','>','&'),array('"','<','>','&'),$string); 33 } 34 $string = recode_string("gb18030..html",$string); 35 // if string sanitizing is not needed, undo htmlspecialchars applied by recode. 36 if ($save_html) { 37 $string=str_replace(array('"','<','>','&'),array('"','<','>','&'),$string); 38 } 39 return $string; 40 } 41 42 /* 43 * iconv does not support html target, but internal utf-8 decoding is faster 44 * than pure php implementation. 45 */ 46 if (function_exists('iconv') && file_exists(SM_PATH . 'functions/decode/utf_8.php') ) { 47 include_once(SM_PATH . 'functions/decode/utf_8.php'); 48 $string = iconv('gb18030','utf-8',$string); 49 return charset_decode_utf_8($string); 50 } 51 52 // mbstring does not support gb18030 53 54 // pure php decoding is not implemented. 55 return $string; 56} 57