Why is the TXT file having problems using file_put_contents?

Asked

Viewed 180 times

-1

I am creating files with the "file_put_contents" function of PHP, on my machine it opens normal in Notepad++, but when sending to someone and it will open in ultra Edit it asks "Do you want to Convert 'file.txt' to DOS format?"

The function I’m using in a simple way

$dados  = "Olá mundo!";
file_put_contents("arquivo.txt", $dados, FILE_APPEND);

How to fix it, I’ve looked on the web but I haven’t seen anything I might be doing wrong.

Error screen:

inserir a descrição da imagem aqui

  • I didn’t understand the problem. It would be the encounter?

  • So boy, I’m trying to see where the bug is, like in my normal open machine I’m getting it.

  • What happens on ultra Edit? he just asks that or the file gets messed up?

  • The user just sent me the error photo, it should not show this error.

  • Put that image in the question.

  • I pasted the image in the theme

  • When you click on does not happen what? does not seem to be an error, just a suggestion to change the file Find.

  • Have you tried other programs besides these two? The problem may not be the file since you said that in Notepad++ it opens..

  • 2

    It is probably the encoding of 'a'. However, put a line break at the end as well. Try saving your PHP as win-1252 in your code editor and see if it solves the problem.

  • 1

    While Crashed Save is just restart or reinstall application. By Thank You For Negative, it is full Noob!

Show 5 more comments

1 answer

0

See if this solves your problem:

<?php 

$dados  = "Olá mundo!";
$copy_utf16 = iconv("UTF-8", "UTF-16LE", $dados);
file_put_contents("arquivo.txt", $copy_utf16, FILE_APPEND);

?>

Look at Soen’s question

  • Should not change Unicode, can problem other operating system, recommend using mb_convert_encoding

Browser other questions tagged

You are not signed in. Login or sign up in order to post.