$string = iconv("UTF-8", "UTF-8//IGNORE", $string);
I thought this code would remove invalid UTF-8 characters, but it produces [E_NOTICE] "iconv(): Detected an illegal character in input string"
. What am I missing, how do I properly strip a string from illegal characters?
The output character set (the second parameter) should be different from the input character set (first param). If they are the same, then if there are illegal UTF-8 characters in the string, iconv
will reject them as being illegal according to the input character set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With