Exemplo n.º 1
0
 /**
  * Convert a string between charsets. XML will always be UTF-8
  *
  * @access	private
  * @param	string		Input String
  * @param	string		Current char set
  * @param	string		Destination char set
  * @return	string		Parsed string
  * @todo 	[Future] If an error is set in classConvertCharset, show it or log it somehow
  */
 private function _convertCharsets($text, $original_cset, $destination_cset = "UTF-8")
 {
     $original_cset = strtolower($original_cset);
     $destination_cset = strtolower($destination_cset);
     $t = $text;
     //-----------------------------------------
     // Not the same?
     //-----------------------------------------
     if ($destination_cset == $original_cset) {
         return $t;
     }
     if (!is_object(self::$classConvertCharset)) {
         Yii::import('ConvertCharset');
         self::$classConvertCharset = new ConvertCharset();
         //-----------------------------------------
         // Ok, mb functions only support limited number
         // of charsets, so if mb functions are enabled
         // but using e.g. windows-1250, no conversion
         // ends up happening.  Let's force internal.
         //-----------------------------------------
         //if ( function_exists( 'mb_convert_encoding' ) )
         //{
         //	self::$classConvertCharset->method = 'mb';
         //}
         //else if ( function_exists( 'iconv' ) )
         //{
         //	self::$classConvertCharset->method = 'iconv';
         //}
         //else if ( function_exists( 'recode_string' ) )
         //{
         //	self::$classConvertCharset->method = 'recode';
         //}
         //else
         //{
         self::$classConvertCharset->method = 'internal';
         //}
     }
     $text = self::$classConvertCharset->convertEncoding($text, $original_cset, $destination_cset);
     return $text ? $text : $t;
 }