encoding problem with csv/excel

Reply

Join Date: Dec 2007
Posts: 3
Reputation: farukruet is an unknown quantity at this point 
Solved Threads: 0
farukruet farukruet is offline Offline
Newbie Poster

encoding problem with csv/excel

 
0
  #1
Dec 10th, 2007
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 ";

}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: black_ip82 is an unknown quantity at this point 
Solved Threads: 0
black_ip82's Avatar
black_ip82 black_ip82 is offline Offline
Newbie Poster

Re: encoding problem with csv/excel

 
0
  #2
Dec 10th, 2007
Did ur Excel installed with arabic text compatibility?
Last edited by black_ip82; Dec 10th, 2007 at 4:37 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: farukruet is an unknown quantity at this point 
Solved Threads: 0
farukruet farukruet is offline Offline
Newbie Poster

Re: encoding problem with csv/excel

 
0
  #3
Dec 10th, 2007
Originally Posted by black_ip82 View Post
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 ?
Last edited by farukruet; Dec 10th, 2007 at 6:10 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 160
Reputation: w_3rabi is an unknown quantity at this point 
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: encoding problem with csv/excel

 
0
  #4
Dec 10th, 2007
you could change the encoding of the page from utf-8 to windows-1256
i guess that would work better
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: farukruet is an unknown quantity at this point 
Solved Threads: 0
farukruet farukruet is offline Offline
Newbie Poster

Re: encoding problem with csv/excel

 
0
  #5
Dec 10th, 2007
Originally Posted by w_3rabi View Post
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');
?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC