9
I battled with this for almost a day and then found that this function will work 100% of the time. It works with utf-8 and unicode and converts characters that are beyond the base ascii set into their html entities. It's good for cleaning up MS Word rubbish.
function filterText($text)
{
//UTF-8 filter
$conv = array(
"\xC2\xA0" => ' ',
"\xC2\xA1" => '¡',
"\xC2\xA2" => '¢',
"\xC2\xA3" => '£',
"\xC2\xA4" => '¤',
"\xC2\xA5" => '¥',
"\xC2\xA6" => '¦',
"\xC2\xA7" => '§',
"\xC2\xA8" => '¨',
"\xC2\xA9" => '©',
"\xC2\xAA" => 'ª',
"\xC2\xAB" => '«',
"\xC2\xAC" => '¬',
"\xC2\xAD" => '­',
"\xC2\xAE" => '®',
"\xC2\xAF" => '¯',
"\xC2\xB0" => '°',
"\xC2\xB1" => '±',
"\xC2\xB2" => '²',
"\xC2\xB3" => '³',
"\xC2\xB4" => '´',
"\xC2\xB5" => 'µ',
"\xC2\xB6" => '¶',
"\xC2\xB7" => '·',
"\xC2\xB8" => '¸',
"\xC2\xB9" => '¹',
"\xC2\xBA" => 'º',
"\xC2\xBB" => '»',
"\xC2\xBC" => '¼',
"\xC2\xBD" => '½',
"\xC2\xBE" => '¾',
"\xC2\xBF" => '¿',
"\xC3\x80" => 'À',
"\xC3\x81" => 'Á',
"\xC3\x82" => 'Â',
"\xC3\x83" => 'Ã',
"\xC3\x84" => 'Ä',
"\xC3\x85" => 'Å',
"\xC3\x86" => 'Æ',
"\xC3\x87" =>