ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech
تاريخ النشر: 2013/04/10
Zaid Rabab'a
من قبل 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
من قبل 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
من قبل 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

مستخدم محذوف‎
من قبل مستخدم محذوف‎

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
من قبل Sami Abu Hamam , Senior Full Stack , Vertex Gaming

use UTF8 encode in output results, it will work.

Faizan Ahmad
من قبل Faizan Ahmad , Software Engineer , cardekho.com

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

المزيد من الأسئلة المماثلة