PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2013, 09:22 PM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Arabic characters doesn't appear in exported excel file

PHP Code:
<?php
mysql_query
("set names utf8");


mysql_connect('localhost','root','admin');
mysql_select_db('mms');

        
$result=mysql_query("select * from test");
        function 
xlsBOF()
        {
        echo 
pack("ssssss"0x8090x80x00x100x00x0);
        return;
        }
        function 
xlsEOF()
        {
        echo 
pack("ss"0x0A0x00);
        return;
        }
        function 
xlsWriteNumber($Row$Col$Value)
        {
        echo 
pack("sssss"0x20314$Row$Col0x0);
        echo 
pack("d"$Value);
        return;
        }
        function 
xlsWriteLabel($Row$Col$Value )
        {
        
$L strlen($Value);
        echo 
pack("ssssss"0x204$L$Row$Col0x0$L);
        echo 
$Value;
        return;
        }
        
header("Pragma: public");
        
header("Expires: 0");
        
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
header("Content-Type: application/force-download");
        
header("Content-Type: application/octet-stream");
        
header("Content-Type: application/download");;
        
header("Content-Disposition: attachment;filename=list.xls");
        
header("Content-Transfer-Encoding: binary ");
        
xlsBOF();
         
        
xlsWriteLabel(0,0,"id");
        
xlsWriteLabel(0,1,"name");
        
$xlsRow 1;
        while(
$row=mysql_fetch_array($result))
        {
        
xlsWriteNumber($xlsRow,0,$row['id']);
        
xlsWriteLabel($xlsRow,1,$row['name']);
        
$xlsRow++;
        }
        
xlsEOF();
        
?>

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.

Reply With Quote
  #2  
Old February 5th, 2013, 10:14 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 35 m 32 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Almost had that. Paste your code into the textarea, select it, then hit the PHP code button.

You can't do a SET NAMES before you've connected to the server. Try moving that.

Reply With Quote
  #3  
Old February 5th, 2013, 10:48 PM
ITechonology ITechonology is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: India
Posts: 2 ITechonology New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 19 m 9 sec
Reputation Power: 0
Send a message via ICQ to ITechonology Send a message via AIM to ITechonology Send a message via Yahoo to ITechonology Send a message via Google Talk to ITechonology Send a message via Skype to ITechonology Send a message via XFire to ITechonology
Bebo Facebook MySpace Orkut
requinix is right ...
Try this one and check it
It's work.
I checked and use it.
Comments on this post
ptr2void disagrees: Gonna guess you're another Indian body shop spammer/SEO.

Reply With Quote
  #4  
Old February 5th, 2013, 10:59 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,847 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
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.

Reply With Quote
  #5  
Old February 5th, 2013, 11:23 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
PHPExcel is one such library that will make that code a lot cleaner and make your spreadsheet more compatible at the same time.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #6  
Old February 6th, 2013, 08:23 AM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Quote:
Originally Posted by requinix
Almost had that. Paste your code into the textarea, select it, then hit the PHP code button.

You can't do a SET NAMES before you've connected to the server. Try moving that.

i have moved it and modified as following

mysql_connect('localhost','root','admin');
mysql_select_db('mms');
mysql_query("set names utf8");

but the output becamse Ù…Ø*مد instead of ?????? any suggestions

Reply With Quote
  #7  
Old February 6th, 2013, 08:24 AM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old February 6th, 2013, 08:25 AM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 40 sec
Reputation Power: 2
Quote:
Originally Posted by E-Oreo
PHPExcel is one such library that will make that code a lot cleaner and make your spreadsheet more compatible at the same time.

can you give me a link or tutorial ?

Reply With Quote
  #9  
Old February 6th, 2013, 01:10 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,847 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
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).

Reply With Quote
  #10  
Old February 6th, 2013, 06:14 PM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #11  
Old February 6th, 2013, 07:05 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,847 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
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).

Reply With Quote
  #12  
Old February 7th, 2013, 09:03 AM
wama_mms wama_mms is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 37 wama_mms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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).

ok thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Arabic characters doesn't appear in exported excel file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap