473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

export arabic data to csv format

52 New Member
Dear Sir,

I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could still see all the arabic text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the arabic text are busted and no longer readable.
arabic text is inserted and stored in database as UTF-8 format.

Do you know a solution for this, how could I make it work OK on MS Excel, because the user want it to view the CSV file in Excel and this is so much urgent for me . please reply.

Regards,
Fauk Chowdhury.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. // Connect to database
  4. mysql_connect("localhost", "root", "root123");
  5. mysql_select_db("medgulf");
  6.  
  7.  $fname = date("d-m-Y");
  8. // mention the file name to display in download prompt
  9. $file_name = "$fname.csv";
  10.  
  11. header("Content-Disposition: attachment; filename=\"$file_name\"");
  12. header("Cache-Control: cache, must-revalidate");
  13. header("Pragma: public");
  14. header('Content-Type: text/xml,  charset=UTF-8; encoding=UTF-8');
  15.  
  16. $fd1 = $_POST['fd'];
  17. $fm1 = $_POST['fm'];
  18. $fy1 = $_POST['fy']; 
  19. // Output header
  20. //echo "Name, Code"."\n";
  21. $frmday = $fy1."-".$fm1."-".$fd1;
  22. $ld1 = $_POST['ld'];
  23. $lm1 = $_POST['lm'];
  24. $ly1 = $_POST['ly']; 
  25.  
  26. $today = $ly1."-".$lm1."-".$ld1;
  27. //echo $frmday;
  28. $usrname = $_POST['usname'];
  29. $export_date = date("Y-m-d");
  30.  
  31. $result = mysql_query("SELECT product, agent_code, policy_no, DATE_FORMAT(entry_date, '%d/%m/%Y'), DATE_FORMAT(inception_date_eng, '%d/%m/%Y'), DATE_FORMAT(inception_date_hijri, '%d/%m/%Y'), DATE_FORMAT(expiry_date_eng, '%d/%m/%Y'), DATE_FORMAT(expiry_date_hijri, '%d/%m/%Y'), client_info.first_name, client_info.family_name, client_info.father_name, client_info.grand_father_name, client_info.mobile_no, client_info.dob, client_info.p_o_box, client_info.zip_code, client_info.city, client_info.id_type, client_info.id_no, vehicle_type, license_type, net_premium, brandname, model, reg_type, plate_no, model_year, chassis_no, color, user_name, age_limit  FROM vehicle_info, client_info where vehicle_info.policy_no = client_info.sr AND entry_date BETWEEN '$frmday' AND '$today' AND  user_name='$usrname' AND exported='yes' ");
  32. $str = mb_convert_encoding($result, "UTF-8", "ASCII");
  33. echo "encode $str";
  34.  
  35. if($result) {
  36. while($rs = mysql_fetch_array($result))
  37. {    echo $rs[0].", ";
  38.     echo $rs[1].", ";
  39.     echo $rs[2].", ";
  40.     echo $rs[3].", ";
  41.     echo $rs[4].", ";
  42.     echo $rs[5].", ";
  43.     echo $rs[6].", ";
  44.     echo $rs[7].", ";
  45.     echo $rs[8].", ";
  46.     echo $rs[9].", ";
  47.     echo $rs[10].", ";
  48.     echo $rs[11].", ";
  49.     echo $rs[12].", ";
  50.     echo $rs[13].", ";
  51.     echo $rs[14].", ";
  52.     echo $rs[15].", ";
  53.     echo $rs[16].", ";
  54.     echo $rs[17].", ";
  55.     echo $rs[18].", ";
  56.     echo $rs[19].", ";
  57.     echo $rs[20].", ";
  58.     echo $rs[21].", ";
  59.     echo $rs[22].", ";
  60.     echo $rs[23].", ";
  61.     echo $rs[24].", ";
  62.     echo " ".", ";
  63.     echo $rs[25].", ";
  64.     echo $rs[26].", ";
  65.     echo $rs[27].", ";
  66.     echo $rs[28].", ";
  67.     echo " ".", ";
  68.     echo " ".", ";
  69.     echo $rs[29].", ";
  70.     echo $rs[30].", ";
  71. }
  72.  
  73. $result4 = mysql_query("UPDATE vehicle_info SET exported ='yes', exported_date='$export_date'   WHERE user_name ='$usrname'");
  74.  
  75. if (!$result4) {
  76.            die('Query failed: To Vehicle Info Table ');
  77.             }
  78.  
  79.  
  80. }
  81. else {
  82.  
  83. echo "There Is No Data To Export ";
  84.  
  85. }
  86.  
  87.  
  88. ?>
Dec 10 '07 #1
2 16524
pbmods
5,821 Recognized Expert Expert
Heya, Fauk.

Make sure you're setting your MySQL connection encoding:
Expand|Select|Wrap|Line Numbers
  1. mysql_query("SET NAMES 'utf-8'", $conn);
  2. mysql_query("SET CHARACTER SET 'utf-8'", $conn);
  3.  
Where $conn is your MySQL connection resource.
Dec 23 '07 #2
unus29
1 New Member
Dear Faruk,

You can use phpexcel library for this purpose. Its works great. You can download the library from here:
http://code.google.com/p/php-excel/

The sample code is as follows (I used that in joomla):
function export_contact_ messages() {
$model = $this->getModel('user contacts');

$rows = $model->getContactMess ages();
global $mosConfig_abso lute_path;

if( !file_exists( $mosConfig_abso lute_path . '/libraries/phpexcel/PHPExcel.php') ) {
die('Phpexcel library not found');
}
$phpexcel_path = $mosConfig_abso lute_path . '/libraries/phpexcel/PHPExcel.php';
include_once($p hpexcel_path);

//die($phpexcel_p ath);

$objPHPExcel = new PHPExcel();

$objPHPExcel->getProperties( )->setCreator("Ti tle")
->setLastModifie dBy("Title")
->setTitle("Cont act Message")
->setSubject("Co ntact Message");



$objPHPExcel->setActiveSheet Index(0)
->setCellValueBy ColumnAndRow(0, 1, "Name")
->setCellValueBy ColumnAndRow(1, 1, "Email")
->setCellValueBy ColumnAndRow(2, 1, "Message")
->setCellValueBy ColumnAndRow(3, 1, "Posted");

$row_count = 2;
foreach ($rows as $row) {
$objPHPExcel->setActiveSheet Index(0)
->setCellValueBy ColumnAndRow(0, $row_count, $row->name)
->setCellValueBy ColumnAndRow(1, $row_count, $row->email)
->setCellValueBy ColumnAndRow(2, $row_count, $row->message)
->setCellValueBy ColumnAndRow(3, $row_count, $row->created_at);
$row_count++;
}

// Rename sheet
$objPHPExcel->getActiveSheet ()->setTitle('cont act_message');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheet Index(0);

ob_clean();
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;file name="contract_ messages.xls"') ;
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFact ory::createWrit er($objPHPExcel , 'Excel5');
$objWriter->save('php://output');
exit;
}
Jun 20 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7456
by: zahid | last post by:
Hello, Dear Friends, I have to make such type of interface,you can say it a html form. in which a admin can write arabic data and can insert that data or recordsin database in ASP. and i have to make a show.asp in which user can see that arabic data in table from database on internet. FOR english version i have make that project completely.
1
1842
by: Do Park via SQLMonster.com | last post by:
Hello all, I don?t often export data from a table. I am wondering how you export data from a table. I?d like to know how you export in real world. Do you export data from a table to a flat file or what type? There are many selections when you choose file type. When do you need to export data? How often? Do you use DTS rather than export wizard?
1
2159
by: cab2 | last post by:
We currently have an application built in Access that takes in a csv file using docmd.transfertext. We allow users to export their data to a file for later use (csv format). Users are also allowed to re-import their archived data. This all works fine, until we have to update the application for international users. The original csv files sent to users contain dates and numbers in US format. However, once imported, the numbers appear...
5
8667
by: Igor | last post by:
Hi everyone! I have a question about exporting data to Microsoft Excel. I am writing program in C# and have to export some data to excel workbook. It works very good using OLE technology, but it requires Microsoft Excel installed on every machine with my program. It is not quite convenient to do so. Is there another way to export data to Excel, or how simply create file of Microsoft Excel format from my program (of cause, the format of...
4
2010
by: Arif | last post by:
My programs searches the header of input barcode in index file. Get the record position next to Barcode header. Then moves the file pointer of products file to reach that record. My products file contains records as follows: 9N-F1T0153|002002820327|Data Switch|EA|00030900|00000 36-EPSON7753|010343600003|حنمبر طابعه 500/570|EA|00001200|00000 ER-270019|013388270019|بقتال الشارع|EA|00019900|00000
1
2635
by: samsadi | last post by:
Hi every one , I am using ASP to export database data to excel file. However, the database table contains special charecters like arabic charecters which is not being exported to excel properly. Is there anyway to acheive this. can any one help ?? I used the below way: <%@ Language=VBScript CodePage = "1256"%> <html dir="rtl"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
4
4901
by: Max2006 | last post by:
Hi, We are developing a SQL server based asp.net application. As part of requirement we should allow users import/export some relational data through web user interface. We are investigation which file format would be the most efficient format to import export relational data. So far we came up with two options: XML and Access MDB files and we prefer MDB files.
1
4635
by: hash4sp | last post by:
Hello ! DBF file consists of a field i.e."districts" which holds data in Arabic language. DBF file is in ANSI format. How to convert this ANSI format so that it displays actual Arabic text on the browser. There is nothing like ANSI encoding in .Net. I could only find ASCII, Unicode, etc. Please give some suggestions or solution to this problem. Please reply asap.. very urgent for me... Thanks in advance!
1
1888
by: farukcse | last post by:
Dear Sir, I am facing a problem with exporting data . when i exported data the arabic characters comes with a invalid character set . i used utf8 encoding systeme in both of php files. so can any one tell me how can i keep the arabic text in a .csv xcel file after exporting? please reply. Regards, Faruk Chowdhury. eader("Content-Disposition: attachment; filename=\"$file_name\""); header("Cache-Control: cache, must-revalidate");...
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.