Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech
Date de publication: 2013/04/10
Zaid Rabab'a
par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

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
par 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
par 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

Utilisateur supprimé
par Utilisateur supprimé

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?

Sami Abu Hamam
par Sami Abu Hamam , Senior Full Stack , Vertex Gaming

use UTF8 encode in output results, it will work.

Faizan Ahmad
par 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