title: PHP: Updating Twitter status while keeping special characters intact
body: <p>On this page...</p>
  
  <p><a href="http://www.axisofeco.com/matters/2010/03/11/the-word-youre-looking-for-is-sublime/" rel="nofollow noreferrer">http://www.axisofeco.com/matters/2010/03/11/the-word-youre-looking-for-is-sublime/</a></p>
  
  <p>... 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). </p>
  
  <p>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: </p>
  
  <p>8217;re+looking+for+is+&#8220;sublime&#8221;+<a href="http://is.gd/acIW2" rel="nofollow noreferrer">http://is.gd/acIW2</a></p>
  
  <p>(if quotes are actually looking ok in the above line, trust me, they stay encoded when Twitter tries to deal with them!)</p>
  
  <p>The relevant PHP for formatting the Twitter update is this:</p>
  
  <pre><code>$url = str_replace(' ', '+', $url); 
  echo htmlentities($url, ENT_COMPAT, 'UTF-8');
  </code></pre>
  
  <p>I've tried using different functions, for example, using urlencode(), but nothing seems to encode the string ($url) in a 'Twitter friendly' manner.</p>