0

how do i force to set charset while writing to a file setting charset 1256 in php i have some data in sql which reads as ÇáÓáÇã Úáíßã æÑÍãå Çááå æÈÑßÇÊå and i am trying to convert it into correct (Arabic) format charset Windows-1256

my code is

$text = "ÇáÓáÇã Úáíßã æÑÍãå Çááå æÈÑßÇÊå";
$file = fopen("test.txt","w");
fwrite($file, $text);
fclose($file);

it saves the data same as it is although it display in correct format on browser i want to save it into text or maybe CSV as السلام عليكم ورحمه الله وبركاته يا اخوان هذا الفيروس which is its correct format

iCodeCrew
  • 115
  • 1
  • 9

2 Answers2

2

Did you try iconv() ?

echo iconv('WINDOWS-1256', 'UTF-8', "ÇáÓáÇã Úáíßã æÑÍãå Çááå æÈÑßÇÊå");
Tomasz
  • 4,847
  • 2
  • 32
  • 41
  • it worked fine however if i put this file into sql table field it becomes more gabrish like السلام عليكم ورحمه الله can you help please – iCodeCrew Aug 25 '15 at 20:08
  • It might be related to encoding of your db. I will suggest to check encoding of file which you are importing into db and also make sure your encoding of dbare correct. – Tomasz Aug 26 '15 at 08:37
0

Use iconv() function.

Example:

fwrite( $file, iconv('UTF-8', 'Windows-1256', $text) );

From UTF-8 to Windows-1256

SarDau Mort
  • 187
  • 4