Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Facing an issue with exporting Arabic data in CSV file using PHP. Any solution?

I am exporting my data from database into a .CSV file using PHP. My data has some Arabic content, CSV is being exported correctly with some garbage Arabic content. How can I correctly write Arabic content in CSV file?

user-image
Question added by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech
Date Posted: 2013/04/10
Zaid Rabab'a
by Zaid Rabab'a , Technical Team Lead , ESKADENIA Software

check mySql connection encoding this may solve the issue try this mysql_query("SET CHARACTER SET 'utf-8'", $Your Connection); mysql_query("SET NAMES 'utf-8'", $Your Connection); i think utf-8 encoding will solve arabic content issue

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Hello Everyone, I have found a solution which worked for me so I thought I should share it with you guys.
header('Content-Encoding: UTF-8'); header('Content-type: text/csv; charset=UTF-8'); header('Content-Disposition: attachment; filename=Customers_Export.csv'); echo "\xEF\xBB\xBF"; // UTF-8 BOM echo $your_data; exit(0); This code helped me in writing Arabic content in CSV file.
Thank You.

Muhammad Bilal Ahmed
by Muhammad Bilal Ahmed , Senior Front End Developer , Seven Software Development

By default, CSVs support US ASCII, however the charset parameter can be used to set the encoding according to the standard.
I did some searching and found this on stack overflow.
It's a good place to start...
http://goo.gl/AaKuU

Deleted user
by Deleted user

First You should check your character encoding when connecting to database, is it the same as data stored in database? The second - does Your editor is set the same charset as data in it?

with the heip of browse file

Sami Abu Hamam
by Sami Abu Hamam , Senior Software Engineer , BMC – IARDA Projec

use UTF8 encode in output results, it will work.

Faizan Ahmad
by Faizan Ahmad , Software Engineer , cardekho.com

Open your CSV file in a text editor check wheather it show correctly or not..

More Questions Like This