1
I am using the code below to generate a txt file but 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);
?>
1
I am using the code below to generate a txt file but 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);
?>
1
A solution would be to open the file (wb
) in binary mode and output to utf8 no fwrite
with utf8_encode
as in this reply from Soen.
I haven’t tested it on my machine yet, but it would be something like this:
<?php
$fid = fopen("bloco.txt", "wb")
fwrite($fid, utf8_encode("é"));
fclose($fid);
Browser other questions tagged php txt fopen
You are not signed in. Login or sign up in order to post.
I tested here, I opened the txt and there is the accented letter
é
– user60252
you’re right, the problem is when I display the file on the screen.Isn’t that a problem? I will consume it and save the information in the database.
– Xiro Nakamura