954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

encoding problem with csv/excel

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 ";

}

farukruet
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Did ur Excel installed with arabic text compatibility?

black_ip82
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
Did ur Excel installed with arabic text compatibility?

Yeah Excel is installed with arabic text compatibility and i can view other arabic text .there is no problem with that. so please tell me where is my problem ?

farukruet
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

you could change the encoding of the page from utf-8 to windows-1256
i guess that would work better

w_3rabi
Junior Poster
160 posts since Dec 2006
Reputation Points: 18
Solved Threads: 9
 
you could change the encoding of the page from utf-8 to windows-1256 i guess that would work better

Dear Sir,
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');
?>

farukruet
Newbie Poster
3 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

hi ...

i still have the same probleme i've triyed a lot of solutions such us the file encoding also functions of encodin (utf8_encode, utf8_decode ...) but does'nt work please i'm in this probleme since 3 days plz if you have a solution i'll be so glade

benmokhtar.med
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

try to set charset at the head of the page that displays the output as UTF-8, saving the data to the excel and displaying it has nothing wrong.
just use utf-8 at the page you echo on.

Adiga911
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Its a problem with how excel deals with your file. If it has to be used in excel then you can ask the user to use the Import functionality under "Data" tab where Excel allows us to specify the encoding. Select UTF-8 as encoding and you would be able to see the characters properly.

Rangan_123
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Just rename the file to .txt and then try to open in excel. It will ask you about the encoding. Then it should be fine. For some reason if you open the file as .csv, then excel cann't figure out the correct encoding. Bugs from Microsoft. I had the same issue.

jazzerman
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You