How to save text in a txt with fwrite in php

1

In the following example, I save the content I want in a txt file, until here it works perfectly, the problem that the txt file creates in asci format and saves the content with strange characters.

If you can help me, super grateful. Greetings.

$file=fopen("1.txt","w+");

fwrite($archivo,"guardar texto? ë ì ?");

fclose($file);
    
asked by juan pablo 02.01.2019 в 18:55
source

2 answers

3

Try as follows:

<?php

header('Content-type: text/html; charset=utf-8'); 

$archivo = fopen("2.txt", "a") or die("Error al crear el txt");

$txt = "guardar texto? ë ì ? ñ ñ"; 

fwrite($archivo,$txt); 

fclose($archivo);

    
answered by 02.01.2019 / 19:13
source
1

Do strange symbols come out when you use accents or Ñ?

If so, it's because of the format, you should set it in UTF-8 .

I recommend editing the question to provide more details.

    
answered by 02.01.2019 в 19:00