943,712 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 31009
  • PHP RSS
Dec 10th, 2007
0

encoding problem with csv/excel

Expand Post »
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 ";

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
farukruet is offline Offline
3 posts
since Dec 2007
Dec 10th, 2007
0

Re: encoding problem with csv/excel

Did ur Excel installed with arabic text compatibility?
Last edited by black_ip82; Dec 10th, 2007 at 4:37 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
black_ip82 is offline Offline
15 posts
since Nov 2007
Dec 10th, 2007
0

Re: encoding problem with csv/excel

Click to Expand / Collapse  Quote originally posted by black_ip82 ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
farukruet is offline Offline
3 posts
since Dec 2007
Dec 10th, 2007
0

Re: encoding problem with csv/excel

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

Re: encoding problem with csv/excel

Click to Expand / Collapse  Quote originally posted by w_3rabi ...
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');
?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
farukruet is offline Offline
3 posts
since Dec 2007
Mar 4th, 2010
0
Re: encoding problem with csv/excel
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
benmokhtar.med is offline Offline
1 posts
since Mar 2010
Aug 9th, 2010
0
Re: encoding problem with csv/excel
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Adiga911 is offline Offline
1 posts
since Aug 2010
Oct 21st, 2010
0
Re: encoding problem with csv/excel
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Rangan_123 is offline Offline
1 posts
since Oct 2010
Oct 23rd, 2010
0
Re: encoding problem with csv/excel
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jazzerman is offline Offline
1 posts
since Oct 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Database to TextArea
Next Thread in PHP Forum Timeline: Warning: Cannot Modify Header





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC