Question

I have created form where you can write text.

In PHP it will get the value of this text field and tries to write it to file:

$txtFile = $filePath.$counter."_ans.txt";
$f=fopen($txtFile, "wb");
fwrite($f, $word);
fclose($f);

When I write text in my language, for example қазақ

I launch it. It created .txt file but when I open it, it shows me: қазақ

Question: What I have to do? My Language is Kazakh.

Was it helpful?

Solution

You need to encode your file in UTF-8 you have two solution :

 header('Content-Type: text/html; charset=utf-8'); // Server side

Or

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> // Client side

On the top of your file.

OTHER TIPS

You can try add a BOM (Byte Order Mark) to your file (and open in html format):

$txtFile = $filePath.$counter."_ans.txt";
$f=fopen($txtFile, "wb");
$string = "\xEF\xBB\xBF";
$string .= $word;
fwrite($f, $string);
fclose($f);

But first look what in your variables var_dump($word)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top