Problem with accent when generating txt in php

1

I am using the code below to generate a txt file but it is generating a strange code.

<?php
header("Content-Type: text/html; charset=UTF-8",true);
$fp = fopen("bloco.txt", "w");
$eu = 'é';
fwrite($fp, $eu);
fclose($fp);

?>  
    
asked by anonymous 12.09.2018 / 16:47

1 answer

1

One solution would be to open the file ( wb ) in binary mode and encode to utf8 in fwrite with utf8_encode as in this SOEn response .

I have not tested on my machine yet, but it would look something like this:

<?php

$fid   = fopen("bloco.txt", "wb")

fwrite($fid, utf8_encode("é"));
fclose($fid);
    
12.09.2018 / 16:56