Export UTF8 เป็น Excel แล้วตัวอักษรไทย ใช้ไม่ได้

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: Export UTF8 เป็น Excel แล้วตัวอักษรไทย ใช้ไม่ได้

Re: Export UTF8 เป็น Excel แล้วตัวอักษรไทย ใช้ไม่ได้

โดย demonxiii » 16/02/2009 10:24 am

ขอบคุณครับ

แก้ได้แล้วครับ

Re: Export UTF8 เป็น Excel แล้วตัวอักษรไทย ใช้ไม่ได้

โดย mindphp » 14/02/2009 12:59 am

ถ้าจะใช้ เป็น tis620 ลองดูข้อ 3 ที่
https://www.mindphp.com/modules.php?name ... cle&sid=10

Export UTF8 เป็น Excel แล้วตัวอักษรไทย ใช้ไม่ได้

โดย demonxiii » 13/02/2009 3:21 pm

จากโค้ด ที่เคยได้รับไป

โค้ด: เลือกทั้งหมด

<?php

// CONFIG //
$host="localhost";
$database="database";
$username="username";
$password="password";
// Must be a writeable location for file
$output_file="export.csv";

// The query to output to CSV
$sql = "select * from tbl1";
// Support for multi-table select
// $sql = "SELECT * FROM tbl2, tbl1 WHERE tbl1.col1 = tbl2.col2";

//---------------------------------------------------

// Connect database
mysql_connect($host,$username,$password);
mysql_select_db($database);

$result=mysql_query($sql);

$output = '';

// Get a list of all the fields in the table
// $fields = mysql_list_fields($database,$table);
// Count the number of fields
$count_fields = mysql_num_fields($result);

// Put the name of all fields to $out.
for ($i = 0; $i < $count_fields; $i++) 
{
   $field=mysql_fetch_field($result);
   $output.= '"'.$field->name.'",';
}
$output .="\n";

// Add all values in the table to $out.
while ($row = mysql_fetch_array($result)) 
{
   for ($i = 0; $i < $count_fields; $i++) 
   {
      $output .='"'.$row["$i"].'",';
   }
   $output .="\n";
}

// Output the file to the local filesystem.  You could append a 
// date to the filename to keep a record of the exports.

// Open a new output file
$file = fopen ($output_file,'w');
// Put contents of $output into the $file
fputs($file, $output);
fclose($file);

// This line will stream the file to the user rather than spray it across the screen
header("Content-type: application/octet-stream");
// Internet Explorer support 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=report.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $output;
?>
ผมก็ทำออกมาแล้วมีปํญหา คือไฟล์ไม่ซัพพอต ไทยครับ

คือฐานข้อมูลเป็น UTF8 พอ พอต ออกมาเลยไม่เป็นภาษาไทยอะครับ เป็นภาษายึกยือ

มีวิธีแก้ไขไมครับ ติดตรงนี้อย่างเดียว

ข้างบน