PHP Convert Windows-1251 to UTF 8

I have a little html code and I need to convert it to UTF-8.
I use this iconv("windows-1251", "utf-8", $html);

All text is converted correctly, but if the text, for example, is in the <i>...</i> , then it does not convert the text, and I see something like this џѕє°·°‚Њ јЅ

+8
php utf-8 character-encoding windows-1251
source share
5 answers

If you have access to the Multibye package, you can try it. See the PHP page here: http://www.php.net/manual/en/function.mb-convert-encoding.php

 $html_utf8 = mb_convert_encoding($html, "utf-8", "windows-1251"); 
+12
source share

You know, a message like џѕє°·°‚Њ јЅ you see if the encoding for the page is windows-1251 , but the text is encoded in utf-8 .
I saw this problem in one of my projects, so just change the encoding of the changes on the page in utf-8 , and this text will be displayed correctly.

Let me give you some examples:
if the page is in utf-8 , but the text in windows-1251 you will see something like this:
???? ?? ?????? ??? ????? ??? ??????? ?? ????? ???? ??? ?????

if page in windows-1251 , but the text in utf-8 you will see the following:
"њѕ±»ЊЅ‹µ ‚µ»µ„ѕЅ‹";"Apple iPhone 4

+1
source share

I always use manual conversion (by symbol), for example:

 $input= 'ћ±Ђ°‰µЅµ љ°'; $s= str_replace('?','fgr43443443',$input); $s= mb_convert_encoding($s, "windows-1251", "utf-8"); $s= str_replace('fgr43443443','',$s); echo $s; 

ps Do not forget that the encoding of the .php file must be UTF8. also in the HTML header insert the standard declaration for UTF8

 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
0
source share

Most solutions do not convert to single-byte encoding. I use mb_convert_encoding ($ string, 'windows-1251') to convert from UTF-8 in my case.

 function ru2Lat($string) { $rus = array('','','','','','','','','','','','','','','',''); $lat = array('yo','zh','tc','ch','sh','sh','yu','ya','YO','ZH','TC','CH','SH','SH','YU','YA'); $string = str_replace($rus,$lat,$string); $string = strtr($string, "", "ABVGDEZIJKLMNOPRSTUFH_I_Eabvgdezijklmnoprstufh'i'e"); return($string); } function transliterate($string){ if (!is_string($string)) return $string; return ru2lat(mb_convert_encoding($string,'windows-1251')); } function transliterate_array($a){ $c = array_map(transliterate,$a); return $c; } 
0
source share

try this, works for me!

 $result = str_replace ('€', '€' , $result); 
-2
source share

All Articles