Iconv (): incomplete multibyte character detected in input string

Hi, I saw this question asked around the traps, but so far none of the examples that I saw helped me when I tried them. I get the error "iconv (): an incomplete multibyte character was found in the input line , on a specific input. When using the following functions together. Do you have any idea how this error message will disappear. I am trying to convert the input mixed-coding string in UTF8.

function ConvertToUTF8($text){ return iconv(mb_detect_encoding($text, mb_detect_order(), false), "UTF-8//IGNORE", $text); } 

EDITOR: Hello everyone after we looked around the following:

  function ConvertToUTF8($text){ $encoding = mb_detect_encoding($text, mb_detect_order(), false); if($encoding == "UTF-8") { $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8'); } $out = iconv(mb_detect_encoding($text, mb_detect_order(), false), "UTF-8//IGNORE", $text); return $out; } 

You may be able to improve it, but it fixed our mistake.

+6
source share
2 answers

Well, that’s what we work for us.

 function ConvertToUTF8($text){ $encoding = mb_detect_encoding($text, mb_detect_order(), false); if($encoding == "UTF-8") { $text = mb_convert_encoding($text, 'UTF-8', 'UTF-8'); } $out = iconv(mb_detect_encoding($text, mb_detect_order(), false), "UTF-8//IGNORE", $text); return $out; } 
+4
source

the problem is in your value of the mb_detect_encoding function returned by this function is an array. use it separately.

0
source

Source: https://habr.com/ru/post/975980/


All Articles