simple_html_dom
simple_html_dom copied to clipboard
iconv(): Detected an illegal character in input string
I encountered this problem when I use this code.
iconv(): Detected an illegal character in input string
Then i change
$converted_text = iconv($sourceCharset, $targetCharset//IGNORE, $text);
to
$converted_text = iconv($sourceCharset, "$targetCharset//IGNORE", $text);
And then pop up the follow error.
iconv(): Detected an incomplete multibyte character in input string.
Final i change the code to
$converted_text = htmlentities($text, ENT_QUOTES, $targetCharset);
It worked fine.
Is there a better way to solve this problem.
Use mb_convert_encoding instead, like this:
mb_convert_encoding(strip_tags($text, $targetCharset, $sourceCharset)