I just thought I'd share this because it took me a bit of time to figure out tonight.

When members post content with MS Word quotes, etc., and they look funky on our UTF-8 websites, it's because those characters need to be converted to UTF-8. This bit of code worked for me so I thought I'd share.

// Convert ISO-8559-1 characters (and MS Word characters) to UTF8
$string = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $string);

// Run htmlspecialchars accepting UTF-8 characters (on older versions of PHP)
return htmlspecialchars($var, ENT_COMPAT, 'UTF-8');
cereal commented: thanks! +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.