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);
?>
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);
?>
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);