How to clear invalid UTF8 characters in PHP ?

Supposing your want to be sure that $string is composed by valid UTF-8 characters:

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

If you want to remove none ISO-8859-1 characters from this string:

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

If you still have characters you want to be ignored, try this:

$string = recode_string("us..flat", $string);

Discussion

Enter your comment
 
 
 

Recent changes RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki