| | |
encoding problem with csv/excel
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
Dear Sir,
I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could still see all the arabic text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the arabic text are busted and no longer readable.
Do you know a solution for this, how could I make it work OK on MS Excel, because the user want it to view the CSV file in Excel.
Regards,
Fauk Chowdhury.
[CODE]
mysql_connect("localhost", "root", "root123");
mysql_select_db("medgulf");
// mention the file name to display in download prompt
$file_name = "download.txt";
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header('Content-Type: text/xml, charset=UTF-8; encoding=UTF-8');
$fd1 = $_POST['fd'];
$fm1 = $_POST['fm'];
$fy1 = $_POST['fy'];
// Output header
//echo "Name,Code"."\n";
$frmday = $fy1."-".$fm1."-".$fd1;
$ld1 = $_POST['ld'];
$lm1 = $_POST['lm'];
$ly1 = $_POST['ly'];
$today = $ly1."-".$lm1."-".$ld1;
//echo $frmday;
$usrname = $_POST['usname'];
$export_date = date("Y-m-d");
$result = mysql_query("SELECT product,agent_code,policy_no,DATE_FORMAT(entry_date,'%d/%m/%Y'),DATE_FORMAT(inception_date_eng,'%d/%m/%Y'),DATE_FORMAT(expiry_date_eng,'%d/%m/%Y'),DATE_FORMAT(inception_date_hijri,'%d/%m/%Y'),DATE_FORMAT(expiry_date_hijri,'%d/%m/%Y'),client_info.first_name,client_info.family_name,client_info.father_name,client_info.grand_father_name,client_info.mobile_no,client_info.dob,client_info.p_o_box,client_info.zip_code,client_info.city,client_info.id_type,client_info.id_no,license_type,net_premium,brandname,model,reg_type,plate_no,model_year,chassis_no,color,age_limit,user_name FROM vehicle_info,client_info where vehicle_info.policy_no = client_info.sr AND entry_date BETWEEN '$frmday' AND '$today' AND user_name='$usrname' AND exported='no' ");
if($result) {
while($rs = mysql_fetch_array($result))
{
echo $rs[0].",";
echo $rs[1].",";
echo $rs[2].",";
echo $rs[3].",";
echo $rs[4].",";
echo $rs[5].",";
echo $rs[6].",";
echo $rs[7].",";
echo $rs[8].",";
echo $rs[9].",";
echo $rs["family_name"].",";
echo $rs["grand_father_name"].",";
echo $rs["mobile_no"].",";
echo $rs["dob"].",";
echo $rs["p_o_box"].",";
echo $rs["zip_code"].",";
echo $rs["city"].",";
echo $rs["id_type"].",";
echo $rs["id_no"].",";
echo $rs["license_type"].",";
echo $rs["net_premium"].",";
echo $rs["brandname"].",";
echo $rs["model"].",";
echo $rs["reg_type"].",";
echo $rs["plate_no"].",";
echo $rs["model_year"].",";
echo $rs["chassis_no"].",";
echo $rs["color"].",";
echo " ".",";
echo " ".",";
echo $rs["age_limit"].",";
echo $rs["user_name"]."\n";
}
}
else {
echo "There Is No Data To Export ";
}
I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could still see all the arabic text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the arabic text are busted and no longer readable.
Do you know a solution for this, how could I make it work OK on MS Excel, because the user want it to view the CSV file in Excel.
Regards,
Fauk Chowdhury.
[CODE]
mysql_connect("localhost", "root", "root123");
mysql_select_db("medgulf");
// mention the file name to display in download prompt
$file_name = "download.txt";
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header('Content-Type: text/xml, charset=UTF-8; encoding=UTF-8');
$fd1 = $_POST['fd'];
$fm1 = $_POST['fm'];
$fy1 = $_POST['fy'];
// Output header
//echo "Name,Code"."\n";
$frmday = $fy1."-".$fm1."-".$fd1;
$ld1 = $_POST['ld'];
$lm1 = $_POST['lm'];
$ly1 = $_POST['ly'];
$today = $ly1."-".$lm1."-".$ld1;
//echo $frmday;
$usrname = $_POST['usname'];
$export_date = date("Y-m-d");
$result = mysql_query("SELECT product,agent_code,policy_no,DATE_FORMAT(entry_date,'%d/%m/%Y'),DATE_FORMAT(inception_date_eng,'%d/%m/%Y'),DATE_FORMAT(expiry_date_eng,'%d/%m/%Y'),DATE_FORMAT(inception_date_hijri,'%d/%m/%Y'),DATE_FORMAT(expiry_date_hijri,'%d/%m/%Y'),client_info.first_name,client_info.family_name,client_info.father_name,client_info.grand_father_name,client_info.mobile_no,client_info.dob,client_info.p_o_box,client_info.zip_code,client_info.city,client_info.id_type,client_info.id_no,license_type,net_premium,brandname,model,reg_type,plate_no,model_year,chassis_no,color,age_limit,user_name FROM vehicle_info,client_info where vehicle_info.policy_no = client_info.sr AND entry_date BETWEEN '$frmday' AND '$today' AND user_name='$usrname' AND exported='no' ");
if($result) {
while($rs = mysql_fetch_array($result))
{
echo $rs[0].",";
echo $rs[1].",";
echo $rs[2].",";
echo $rs[3].",";
echo $rs[4].",";
echo $rs[5].",";
echo $rs[6].",";
echo $rs[7].",";
echo $rs[8].",";
echo $rs[9].",";
echo $rs["family_name"].",";
echo $rs["grand_father_name"].",";
echo $rs["mobile_no"].",";
echo $rs["dob"].",";
echo $rs["p_o_box"].",";
echo $rs["zip_code"].",";
echo $rs["city"].",";
echo $rs["id_type"].",";
echo $rs["id_no"].",";
echo $rs["license_type"].",";
echo $rs["net_premium"].",";
echo $rs["brandname"].",";
echo $rs["model"].",";
echo $rs["reg_type"].",";
echo $rs["plate_no"].",";
echo $rs["model_year"].",";
echo $rs["chassis_no"].",";
echo $rs["color"].",";
echo " ".",";
echo " ".",";
echo $rs["age_limit"].",";
echo $rs["user_name"]."\n";
}
}
else {
echo "There Is No Data To Export ";
}
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
Last edited by farukruet; Dec 10th, 2007 at 6:10 am.
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
you could change the encoding of the page from utf-8 to windows-1256
i guess that would work better
i added the character set and encoding with windows-1256. but it keeps same problem as before.simply if i send an arabic character i.e echo "س"; then it does not comes at excel shet.so can you tel me l how to send data from php file to excel with utf8 or windows-1256 format. i.e encoding method of sending data.
please reply . this is so much urgent for me.
Regards,
Faruk chowdhury
[code]
<?php
header('Content-Type: text/xml, charset=windows-1256; enucoding=windows-1256');
?>
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: What is a prefix in php?
- Next Thread: PHP Question
| Thread Tools | Search this Thread |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql object oop password paypal pdf php phpincludeissue query radio random recursion recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





