On this page...
http://www.axisofeco.com/matters/2010/03/11/the-word-youre-looking-for-is-sublime/
... I have a 'Tweet this' link which pastes in the article title and a link into your Twitter update box (if you're logged in to Twitter).
Problem is, when articles such as the one above have special characters in them (fancy single / double quotes mostly), Twitter can't seem to handle them. This is what Twitter tries (and fails horribly) to paste into the Twitter update box:
8217;re+looking+for+is+“sublime”+http://is.gd/acIW2
(if quotes are actually looking ok in the above line, trust me, they stay encoded when Twitter tries to deal with them!)
The relevant PHP for formatting the Twitter update is this:
$url = str_replace(' ', '+', $url);
echo htmlentities($url, ENT_COMPAT, 'UTF-8');
I've tried using different functions, for example, using urlencode(), but nothing seems to encode the string ($url) in a 'Twitter friendly' manner.