#1 20.04.06 13:20
[php] декодирование юникода в кирилицу
скрипт парсит файлы и получает результаты частично в win1251, а частично в юникоде. все на русском языке :(
дык вот вопрос простой: как можно из юникода получить win1251 чтобы результат был читаемый. (обратное не предлагать)
utf8_decode смотрел - русский не понимает :(
Исправлено weer (20.04.06 13:20)
Offline
#3 20.04.06 14:03
Re: [php] декодирование юникода в кирилицу
mb_convert_encoding
(PHP 4 >= 4.0.6, PHP 5)
mb_convert_encoding -- Convert character encoding
Description
string mb_convert_encoding ( string str, string to-encoding [, mixed from-encoding])
mb_convert_encoding() converts character encoding of string str from from-encoding to to-encoding.
str : String to be converted.
from-encoding is specified by character code name before conversion. it can be array or string - comma separated enumerated list. If it is not specified, the internal encoding will be used.
Пример 1. mb_convert_encoding() example
<?php
/* Convert internal character encoding to SJIS */
$str = mb_convert_encoding($str, "SJIS");
/* Convert EUC-JP to UTF-7 */
$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win");
/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
$str = mb_convert_encoding($str, "EUC-JP", "auto");
?>
See also mb_detect_order().
Offline
#5 21.04.06 11:39
Re: [php] декодирование юникода в кирилицу
<?php
function utf8win1251($s){
$out = $c1 = "";
$byte2=false;
for ($c=0;$c<strlen($s);$c++){
$i=ord($s[$c]);
if ($i<=127) $out.=$s[$c];
if ($byte2){
$new_c2=($c1&3)*64+($i&63);
$new_c1=($c1>>2)&5;
$new_i=$new_c1*256+$new_c2;
if ($new_i==1025){
$out_i=168;
}
else{
if ($new_i==1105){
$out_i=184;
}
else {
$out_i=$new_i-848;
}
}
$out.=chr($out_i);
$byte2=false;
}
if (($i>>5)==6) {
$c1=$i;
$byte2=true;
}
}
return $out;
}
?>
это не моё, но я этим пользовался, и знаете ли работало!
Просто в код приинклудить этот файл и засунуть в функцию строчку!
Offline
#8 22.04.06 14:58
Re: [php] декодирование юникода в кирилицу
Fatal error: Call to undefined function: mb_convert_encoding() in c:\inetpub\wwwroot\bnethostelstatus\monitoring\mon_begin.inc on line 102
дело в том что модуль mbstring отказывается загружатся, хотя прописан в php.ini и даже скопирован в system32 для гарантии.
в php.ini
Код::
... ; Directory in which the loadable extensions (modules) reside. extension_dir = C:\php4\extensions ... extension=php_mbstring.dll ;extension=php_bz2.dll ;extension=php_cpdf.dll ;extension=php_crack.dll ;extension=php_curl.dll ;extension=php_db.dll ;extension=php_dba.dll ;extension=php_dbase.dll ;extension=php_dbx.dll ;extension=php_domxml.dll ;extension=php_exif.dll ;extension=php_fdf.dll ;extension=php_filepro.dll ;extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_hyperwave.dll ;extension=php_iconv.dll ;extension=php_ifx.dll extension=php_iisfunc.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_java.dll ;extension=php_ldap.dll ;extension=php_mcrypt.dll ;extension=php_mhash.dll extension=php_mime_magic.dll ;extension=php_ming.dll ;extension=php_mssql.dll extension=php_msql.dll ;extension=php_oci8.dll extension=php_openssl.dll ;extension=php_oracle.dll ;extension=php_pdf.dll ;extension=php_pgsql.dll ;extension=php_printer.dll ;extension=php_shmop.dll ;extension=php_snmp.dll extension=php_sockets.dll ;extension=php_sybase_ct.dll extension=php_w32api.dll ;extension=php_xmlrpc.dll ;extension=php_xslt.dll ;extension=php_yaz.dll extension=php_zip.dll ... [mbstring] ; language for internal character representation. mbstring.language = Russian ; internal/script encoding. ; Some encoding cannot work as internal encoding. ; (e.g. SJIS, BIG5, ISO-2022-*) mbstring.internal_encoding = UTF-8 ; http input encoding. mbstring.http_input = auto ; http output encoding. mb_output_handler must be ; registered as output buffer to function mbstring.http_output = CP1251 ; enable automatic encoding translation according to ; mbstring.internal_encoding setting. Input chars are ; converted to internal encoding by setting this to On. ; Note: Do _not_ use automatic encoding translation for ; portable libs/applications. mbstring.encoding_translation = On ; automatic encoding detection order. ; auto means mbstring.detect_order = auto ; substitute_character used when character cannot be converted ; one from another mbstring.substitute_character = none; ; overload(replace) single byte functions by mbstring functions. ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(), ; etc. Possible values are 0,1,2,4 or combination of them. ; For example, 7 for overload everything. ; 0: No overload ; 1: Overload mail() function ; 2: Overload str*() functions ; 4: Overload ereg*() functions ;mbstring.func_overload = 0
Но все равно получаю следующие загруженные модули
Код::
( [0] => standard [1] => bcmath [2] => calendar [3] => ctype [4] => com [5] => ftp [6] => mysql [7] => odbc [8] => overload [9] => pcre [10] => session [11] => tokenizer [12] => xml [13] => wddx [14] => zlib [15] => ISAPI )
у меня есть большое подозрение, что я чего-то не знаю :)
Offline
#10 22.04.06 15:09
Re: [php] декодирование юникода в кирилицу
читай на www.php.net
там есть заметка про iconv и что надо, чтобы грузился модуль
Offline

