title: Encoding MySQL text fields into UTF-8 text files - problems with special characters
body: <p>I'm writing a php script to export MySQL database rows into a .txt file formatted for Adobe InDesign's internal markup.</p>
  
  <p>Exports work, but when I encounter special characters like é or umlauts, I get weird symbols (eg <code>ChloÃ« Hanslip</code> instead of <code>Chloë Hanslip</code>). Rather than run a search and replace for every possible weird character, I need a better method.</p>
  
  <p>I've checked that when the text hits the database, it's saved properly - in the database I see the special characters. My export code basically runs some regular expressions to put in the InDesign code tags, and I'm left with the weird symbols. If I just output the text to the browser (rather than prompt for a text file download), it displays properly. When I save the file I use this code:</p>
  
  <p><code>header("Content-disposition: attachment; filename=test.txt");</code></p>
  
  <p><code>header("Content-Type: text/plain; charset=utf-8");</code></p>
  
  <p>I've tried various combinations of <code>utf8_encode()</code> and <code>iconv()</code> to no avail. Can anybody point me in the right direction here?</p>