Php UTF8中的制表符字符

Php UTF8中的制表符字符,php,mysql,utf-8,xls,Php,Mysql,Utf 8,Xls,我正在尝试创建mysql表的xls文件输出,我需要文件export.php的UTF8编码,因为斯洛伐克字符-ľľťťý。。。但当我将其转换为UTF8时,我的脚本无法打印\t字符 // part of export.php header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=export.xls"); header("Pragma: no-cache"); heade

我正在尝试创建mysql表的xls文件输出,我需要文件export.php的UTF8编码,因为斯洛伐克字符-ľľťťý。。。但当我将其转换为UTF8时,我的脚本无法打印\t字符

// part of export.php

header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=export.xls");
header("Pragma: no-cache");
header("Expires: 0");
$sql = ("select * from zakaznici");
$db->query("SET NAMES 'utf8'");

if (!$result = $db->query($sql))
{
    die('There was an error running the query [' . $db->error . ']');
}

// define separator (defines columns in excel & tabs in word)

$sep = "\t"; //tabbed character

// start of printing column names as names of MySQL fields

$finfo = $result->fetch_fields();

foreach($finfo as $val)
{
    printf("%s\t", $val->name);
}

print ("\n");
$schema_insert = "";

while ($ser = $result->fetch_assoc())
{
    $id = $ser['id'];
    $email = $ser['email'];
    $password = $ser['pass'];
    $schema_insert.= $id . $sep . $email . $sep . $password;
    print ("\n");
}

$schema_insert = str_replace($sep . "$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert.= "\t";
print (trim($schema_insert));
print "\n";
\n.性格很好。。只有使用UTF8的\t不起作用
感谢您的帮助

我的猜测是,UTF-8 BOM标记在生成的BOM表开始时丢失了 文件因此,我建议在内容输出之前添加BOM,如下所示:

print "\xEF\xBB\xBF";
print trim($schema_insert);
print "\n";
有些人建议使用
mb\u convert\u encoding()
,请参见此处: