Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-09-2012, 08:26 AM   PM User | #1
zeemperor
New Coder

 
Join Date: Oct 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
zeemperor is an unknown quantity at this point
exporting from DB to CSV - encoding issues with arabic characters

I’m trying to export from DB content that includes Arabic letters.
When I export to CSV/XLS it appears as ???????? or الØ*مراوي
I use this code:
Code:
$query = "SET NAMES 'utf8' COLLATE 'utf8_general_ci'";
mysql_query($query) or die(mysql_error());


function CSVExport($query,$filename = 'data') {
    $sql_csv = mysql_query($query) or die("Error: " . mysql_error()); 
    header('Content-Type: text/html; charset=UTF-8');
    //header("Content-type: application/vnd.ms-excel");
    header("Cache-Control: cache, must-revalidate");
    header("Pragma: public"); 
    header("Content-type:text/octect-stream");
    header("Content-Disposition:attachment;filename=$filename.csv");
    
    while($row = mysql_fetch_row($sql_csv)) {
        print '"' . stripslashes(implode('","',$row)) . "\"\n";
    }
    exit;
}


 CSVExport("SELECT * from `arabictable`", 'myexportfile');


Anyone has idea how do I fix this? How do I see Arabic letters correctly?
zeemperor is offline   Reply With Quote
Old 10-09-2012, 04:40 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Open that up in an editor that supports utf8. Does it show the characters as expected?
You'll probably need a content-encoding header as well. Not sure why your content type is text/html, that should be either text/csv or application/csv (or even text/plain), but overall that won't make a tremendous difference to an attachment. You may need to transfer in binary for this as well.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:46 AM.


Advertisement
Log in to turn off these ads.