Hello,

I am trying to export mysql tables to excell AND CSV, arabic characters do not work

<?php

/*
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header('Content-Type: text/xml, charset=UTF-8; encoding=UTF-8');
*/

header( 'Content-Type: text/csv; charset=utf-8; encoding=UTF-8' );

header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header( 'Content-Disposition: attachment;filename=export.csv' );
//
// establish database connection
//
$conn = mysql_connect( 'localhost', 'root', '' ) or die( mysql_error( ) );
mysql_select_db( 'labora_donnation', $conn ) or die( mysql_error( $conn ) );
//
// execute sql query
//
$query = sprintf( 'SELECT * FROM pr2' );
$result = mysql_query( $query, $conn ) or die( mysql_error( $conn ) );
//
// send response headers to the browser
// following headers instruct the browser to treat the data as a csv file called export.csv
//
// header('Content-Type: text/html');

//
// output header row (if atleast one row exists)
//
$row = mysql_fetch_assoc( $result );
if ( $row )
{
echocsv( array_keys( $row ) );
}
//
// output data rows (if atleast one row exists)
//
while ( $row )
{
echocsv( $row );
$row = mysql_fetch_assoc( $result );
}
//
// echocsv function
//
// echo the input array as csv data maintaining consistency with most CSV implementations
// * uses double-quotes as enclosure when necessary
// * uses double double-quotes to escape double-quotes
// * uses CRLF as a line separator
//
function echocsv( $fields )
{
$separator = '';
foreach ( $fields as $field )
{
if ( preg_match( '/\\r|\\n|,|"/', $field ) )
{
$field = '"' . str_replace( '"', '""', $field ) . '"';
}
echo $separator . $field;
$separator = ',';
}
echo "\r\n";
}
?>