title: Decoding Windows-1252 characters in imap subject line to UTF-8
body: <p>I have a website that will allow people to post things to it using the subject line of an email in Outlook. Using PHP and imap, I get the subject line of the text and store it in a mysql db. But every once in a while, someone will copy text from a website into the subject line of that email and I will get garbled text. Similar to this:</p>
  
  <p>=?Windows-1252?Q?_Every_day_in_our_offices_we_recycle_cardboard,<em>aluminum?=
  =?Windows-1252?Q?</em>=96_won=92t_you_join_us=3F?=</p>
  
  <p>What I've done is try to decode this text so it will appear normal on the page using the following code:</p>
  
  <pre><code>$subject = strip_tags($mailHeader-&gt;subject);
  $header = imap_mime_header_decode($subject);
  $subject = "";
  for($i=0;$i&lt;count($header);$i++)
  {
      $subject .= $header[$i]-&gt;text;
  }
  </code></pre>
  
  <p>When finished I get rid of most of the garbled text, but am left behind with replacement characters for an em dash and a curly quote that was in the original subject line text. See the result below:</p>
  
  <p>Every day in our offices we recycle cardboard, aluminum, � won�t you join us? </p>
  
  <p>The charset for the website is set to UTF-8. When I set the website charset to ISO-8859-1, the replacement characters are replaced with the curly quote and em dash, which is great but I want to leave the website's charset at UTF-8.</p>
  
  <p>Any help on how to get rid of the replacement characters without changing the charset to ISO-8859-1 would be great. Thanks.</p>