Arabic characters doesn't appear in exported excel file
Discuss Arabic characters doesn't appear in exported excel file in the PHP Development forum on Dev Shed. Arabic characters doesn't appear in exported excel file PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
and i have tried a lot to solve this problem for exporting arabic data in excel sheet as it appears "????" from database but i can't find a solution. so please help me
Last edited by requinix : February 5th, 2013 at 10:11 PM.
Posts: 1,847
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 36 m 10 sec
Reputation Power: 813
Hi,
actually, you mustn't use "SET NAMES" at all, because it's a security risk as it can break mysql_real_escape_string(). The manual has a big yellow warning for that.
Use mysql_set_charset() or change the default encoding on the server. Or even better: Dump the old MySQL extension and switch to one of the modern extensions (unless this script is embedded in a lot of legacy code).
I'd also consider using an Excel library. This byte packing looks horrible.
Posts: 37
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Quote:
Originally Posted by Jacques1
Hi,
actually, you mustn't use "SET NAMES" at all, because it's a security risk as it can break mysql_real_escape_string(). The manual has a big yellow warning for that.
Use mysql_set_charset() or change the default encoding on the server. Or even better: Dump the old MySQL extension and switch to one of the modern extensions (unless this script is embedded in a lot of legacy code).
I'd also consider using an Excel library. This byte packing looks horrible.
thanks for your post but i am just a beginner and don't know what do you mean
Posts: 1,847
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 36 m 10 sec
Reputation Power: 813
Quote:
Originally Posted by wama_mms
thanks for your post but i am just a beginner and don't know what do you mean
Well, like I said: Do not query the database with "SET NAMES". This is wrong and can lead to security problems. The correct way of setting the character encoding is by calling mysql_set_charset(). So in your case, you'd write
PHP Code:
$db_link = mysql_connect('localhost', 'root', 'admin'); // I hope "root" and the password are just for testing ;-)
mysql_select_db('mms');
mysql_set_charset('utf8');
And in addition to that, I said that the "mysql_" functions you're using are obsolete. So if you have the chance to update them, do it (check the link I gave you).
Posts: 37
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Quote:
Originally Posted by Jacques1
Well, like I said: Do not query the database with "SET NAMES". This is wrong and can lead to security problems. The correct way of setting the character encoding is by calling mysql_set_charset(). So in your case, you'd write
PHP Code:
$db_link = mysql_connect('localhost', 'root', 'admin'); // I hope "root" and the password are just for testing ;-)
mysql_select_db('mms');
mysql_set_charset('utf8');
And in addition to that, I said that the "mysql_" functions you're using are obsolete. So if you have the chance to update them, do it (check the link I gave you).
i have added what you said but the output isn't correct it appears as Ù…Ø*مد i am using office 2013
Posts: 1,847
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 36 m 10 sec
Reputation Power: 813
The mysql_set_charset() was a security suggestion (like I said), it wasn't meant to fix the issue.
Have you checked the "raw" data directly after you fetched it from the database? If it's OK there and only broken in the Excel file, it's obviously a problem of your Excel functions. In that case, I strongly suggest using a library (see E-Oreo's post) rather than fumbling with your own home-made functions.
If the data itself is broken, it's an issue of your database (or the input).
Posts: 37
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Quote:
Originally Posted by Jacques1
The mysql_set_charset() was a security suggestion (like I said), it wasn't meant to fix the issue.
Have you checked the "raw" data directly after you fetched it from the database? If it's OK there and only broken in the Excel file, it's obviously a problem of your Excel functions. In that case, I strongly suggest using a library (see E-Oreo's post) rather than fumbling with your own home-made functions.
If the data itself is broken, it's an issue of your database (or the input).