Problem With Turkish Characters

Topics: User Forum
Jun 20, 2013 at 9:40 AM
Hi,

I have set the php page and it works quite fast.

But I have a problem with Turkish characters. And although I set the php script to UTF8 without BOM, when I open the downloaded file in notepad charset looks ANSI. Here is my code:
<?php
$Host = "localhost";
$User = "xxx";
$Password = "";
$DBName = "mydb";
$TableName = "satislar";

$link = mysql_connect ($Host, $User, $Password) or die('Could not connect: ' . mysql_error());
mysql_select_db($DBName) or die('Could not select database');
//mysql_set_charset($link, 'utf8');//if not by default

$select = "SELECT * FROM satislar";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
    
for ($i = 0; $i < $fields; $i++) {
$csv_output .= mysql_field_name($export, $i) . "\t";
}

while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($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/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Aktif2000_Tum_Satislar.xls");
header("Pragma: no-cache");
header("Expires: 0");
print $csv_output."\n".$data;
exit;
?>
Coordinator
Jun 25, 2013 at 3:20 PM
Try writing a UTF-8 BOM marker to your tab-separated value file before you write any data; consider using PHP's built-in fputcsv() function rather than all this str_replace() and writing tabs by hand; remember that a tab-separated value file is not an xls file; and note that this is a site/board for the PHPExcel library, not a general purpose PHP help site.