File with utf8 encoding, create variable

$str = 'ааыв'; file_put_contents('ile.txt', $str , FILE_APPEND); 

And writes the following to the file:

 ааыв 

How to write to the file that the Russian characters were? ..

 mb_detect_encoding($str );// UTF-8 

Via echo, it displays the string correctly, in Russian characters on the page.

    2 answers 2

     $str = 'ааыв'; file_put_contents('ile.txt', iconv('utf-8', 'windows-1251', $str) , FILE_APPEND); 

      try the simplest solution: add it to the top:

       header('Content-Type: text/html; charset=utf-8'); 
      • No, this is what would be displayed on the site in what encoding, the answer below, thanks anyway. - user190134
      • @ user190134 I apologize, I overlooked it. thank you for rating! - Egor Randomize