title: Export MySQL to Unicode txt File
body: <p>I am currently able to export my MySQL query to a tab delimited text file, however it is saving with a UTF8 encoding. A requirement of this project is that it saves as a Unicode-16LE text file.</p>
  
  <p>My current function looks something like this:</p>
  
  <pre><code>$select = "SELECT -removed-";
  $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) );
  $fields = mysql_num_fields ( $export );
  
  for ($i = 0; $i &lt; $fields; $i++) {
    $header .= mysql_field_name( $export , $i ) . "\t";
  }
  
  while ($row = mysql_fetch_row($export)) {
    $line = '';
    foreach ($row as $value) {
      if ((!isset($value)) || ($value == "")) {
        $value = "\t";
      } else {
        $value = str_replace( '"' , '""' , $value );
        $value = '' . $value . '' . "\t";
      }
      $line .= $value;
    }
    $data .= trim( $line ) . "\n";
  }
  
  $data = str_replace( "\r" , "" , $data );
  
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename=my_file.txt");
  header("Pragma: no-cache");
  header("Expires: 0");
  print "$header\n$data";
  </code></pre>
  
  <p>Any advice would be appreciated!</p>
  
  <p>Thanks in advance.</p>