Iconv UTF-8 // IGNORE Still Produces Illegal Symbol Error

$string = iconv("UTF-8", "UTF-8//IGNORE", $string); 

I thought this code would remove invalid UTF-8 characters, but it creates [E_NOTICE] "iconv(): Detected an illegal character in input string" . What am I missing, how to remove a string from illegal characters correctly?

+13
php utf-8 iconv
Feb 21 '12 at 10:29
source share
2 answers

The output character set (second parameter) must be different from the input character set (first parameter). If they match, then if the string contains invalid UTF-8 characters, iconv reject them as illegal according to the set of input characters.

+5
Feb 21 '12 at 10:32
source share

To simply ignore the notification, you can use the "@":

$string = @iconv("UTF-8", "UTF-8//IGNORE", $string);

-one
Nov 13 '13 at 8:41
source share



All Articles