Beispiel #1
0
function nc_win2utf($str)
{
    if (extension_loaded('mbstring')) {
        return mb_convert_encoding($str, "UTF-8", "cp1251");
    }
    if (extension_loaded('iconv')) {
        return iconv('cp1251', 'UTF-8', $str);
    }
    global $_UTFConverter;
    if (!$_UTFConverter) {
        require_once "utf8/utf8.class.php";
        $_UTFConverter = new utf8(CP1251);
    }
    return $_UTFConverter->strToUtf8($str);
}
        $f = 0;
        while ($row = mysql_fetch_array($resultados)) {
            $f++;
            echo '{
								';
            $ruta = 'img=../../repositorio/originales/' . $row['imagen'] . '&id_imagen=' . $row['id_imagen'] . '&id_palabra=' . $row['id_palabra'] . '&id_idioma=' . $id_language;
            $encript->encriptar($ruta, 1);
            $ruta_img = 'size=' . $thumbnailsize . '&ruta=../../repositorio/originales/' . $row['imagen'];
            $encript->encriptar($ruta_img, 1);
            //OJO uno(1) es para encriptar variables para URL
            echo '"imagePNGURL": "http://' . $url_dominio . '/repositorio/originales/' . $row['imagen'] . '",';
            if ($id_language > 0) {
                switch ($id_language) {
                    case 1:
                        //RUSO
                        $word = $utfConverter_ru->strToUtf8($row['traduccion']);
                        break;
                    case 3:
                        //ARABE
                        $word = $utfConverter->strToUtf8($row['traduccion']);
                        break;
                    case 5:
                        //BULGARO
                        $word = $utfConverter_ru->strToUtf8($row['traduccion']);
                        break;
                    default:
                        $word = $row['traduccion'];
                        break;
                }
                $id_tipo_palabra = $row['id_tipo_palabra'];
                echo '"name": "' . $word . '", "wordTYPE": "' . $id_tipo_palabra . '",';
Beispiel #3
0
 /**
  * Convert a string from one charset to another.
  * Uses mbstring and iconv functions if possible
  *
  * @param  string Input string
  * @param  string Suspected charset of the input string
  * @param  string Target charset to convert to; defaults to RCMAIL_CHARSET
  *
  * @return string Converted string
  */
 public static function convert($str, $from, $to = null)
 {
     static $iconv_options = null;
     static $mbstring_loaded = null;
     static $mbstring_list = null;
     static $conv = null;
     $to = empty($to) ? strtoupper(RCMAIL_CHARSET) : $to;
     $from = self::parse($from);
     // It is a common case when UTF-16 charset is used with US-ASCII content (#1488654)
     // In that case we can just skip the conversion (use UTF-8)
     if ($from == 'UTF-16' && !preg_match('/[^\\x00-\\x7F]/', $str)) {
         $from = 'UTF-8';
     }
     if ($from == $to || empty($str) || empty($from)) {
         return $str;
     }
     // convert charset using iconv module
     if (function_exists('iconv') && $from != 'UTF7-IMAP' && $to != 'UTF7-IMAP') {
         if ($iconv_options === null) {
             // ignore characters not available in output charset
             $iconv_options = '//IGNORE';
             if (iconv('', $iconv_options, '') === false) {
                 // iconv implementation does not support options
                 $iconv_options = '';
             }
         }
         // throw an exception if iconv reports an illegal character in input
         // it means that input string has been truncated
         set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE);
         try {
             $_iconv = iconv($from, $to . $iconv_options, $str);
         } catch (ErrorException $e) {
             $_iconv = false;
         }
         restore_error_handler();
         if ($_iconv !== false) {
             return $_iconv;
         }
     }
     if ($mbstring_loaded === null) {
         $mbstring_loaded = extension_loaded('mbstring');
     }
     // convert charset using mbstring module
     if ($mbstring_loaded) {
         $aliases['WINDOWS-1257'] = 'ISO-8859-13';
         if ($mbstring_list === null) {
             $mbstring_list = mb_list_encodings();
             $mbstring_list = array_map('strtoupper', $mbstring_list);
         }
         $mb_from = $aliases[$from] ? $aliases[$from] : $from;
         $mb_to = $aliases[$to] ? $aliases[$to] : $to;
         // return if encoding found, string matches encoding and convert succeeded
         if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {
             if (mb_check_encoding($str, $mb_from) && ($out = mb_convert_encoding($str, $mb_to, $mb_from))) {
                 return $out;
             }
         }
     }
     // convert charset using bundled classes/functions
     if ($to == 'UTF-8') {
         if ($from == 'UTF7-IMAP') {
             if ($_str = self::utf7imap_to_utf8($str)) {
                 return $_str;
             }
         } else {
             if ($from == 'UTF-7') {
                 if ($_str = self::utf7_to_utf8($str)) {
                     return $_str;
                 }
             } else {
                 if ($from == 'ISO-8859-1' && function_exists('utf8_encode')) {
                     return utf8_encode($str);
                 } else {
                     if (class_exists('utf8')) {
                         if (!$conv) {
                             $conv = new utf8($from);
                         } else {
                             $conv->loadCharset($from);
                         }
                         if ($_str = $conv->strToUtf8($str)) {
                             return $_str;
                         }
                     }
                 }
             }
         }
     }
     // encode string for output
     if ($from == 'UTF-8') {
         // @TODO: we need a function for UTF-7 (RFC2152) conversion
         if ($to == 'UTF7-IMAP' || $to == 'UTF-7') {
             if ($_str = self::utf8_to_utf7imap($str)) {
                 return $_str;
             }
         } else {
             if ($to == 'ISO-8859-1' && function_exists('utf8_decode')) {
                 return utf8_decode($str);
             } else {
                 if (class_exists('utf8')) {
                     if (!$conv) {
                         $conv = new utf8($to);
                     } else {
                         $conv->loadCharset($from);
                     }
                     if ($_str = $conv->strToUtf8($str)) {
                         return $_str;
                     }
                 }
             }
         }
     }
     // return original string
     return $str;
 }