I have a file test.HIO its content this:
11/08/2015 00:05:50»ЦО Ворота выход»Дверь не открыта»24001695»Бахром Суннатуллоевич Тургунов»99»»»
11/08/2015 00:05:54»ЦО Ворота выход»Верный доступ»24001215»Шохрух Джохонгирович Исламов»99»»»
If i use linux command file -i test.HIO i get this info:
test.HI0: text/plain; charset=iso-8859-1
If i convert this file use php function iconv or mb_convert_encoding:
$file_content = file( "test.HIO" );
// for example i get one line from file
$str = iconv( "ISO-8859-1", "UTF-8", $file_content[2] );
var_dump( $str );
$str2 = mb_convert_encoding( $file_content[2], "UTF-8", "ISO-8859-1" );
var_dump( $str2 );
I get the same result:
string(159) " 11/08/2015 00:05:45»ÖÎ Âîðîòà âûõîä»Âåðíûé äîñòóï»24001695»Áàõðîì Ñóííàòóëëîåâè÷ Òóðãóíîâ»99»»» "
If i just show file content in browser:
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$file_content = file( "test.HI0" );
echo $file_content[2];
i see this:
11/08/2015 00:07:17��� 2 ����������� �������24001066��������� ���������� �������99���
How correctly show or save text in UTF-8 encode?
Thank in anvance.
UPD.
Thank to all. I find another solution it looks ugly, but working.
$file_content = file( "test.HIO" );
$str = iconv( "ISO-8859-1", "UTF-8", $file_content[2] );
// OR
$str = mb_convert_encoding( $file_content[2], "UTF-8", "ISO-8859-1" );
$str = iconv( 'utf-8', 'windows-1252', $str );
$str = iconv( 'windows-1251', 'utf-8', $str );
var_dump( $str );
UPD 2.
I chose the wrong way using file -i for detect file encoding.
As it turned out, my file encoding is windows-1251
chardet /home/file.HI0
/home/file.HI0: windows-1251 (confidence: 0.75)
or @yangsunny advice enca
enca -L ru /home/file.HI0
MS-Windows code page 1251
Eventually, can be used this code:
$file_content = file( "test.HIO" );
$str2 = mb_convert_encoding( $file_content[2], "UTF-8", "windows-1251" );
var_dump( $str2 );
Thank all for help.
ISO-8859-1, you can useutf8_encodeto convert this to utf8.mb_detect_encoding()with strict mode. Sadly, it doesnt always give the right result.