elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Escribir Archivo UTF8
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Escribir Archivo UTF8  (Leído 9,392 veces)
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Escribir Archivo UTF8
« en: 6 Abril 2022, 21:14 pm »

Hola buenas,

estoy teniendo un problema, tengo la siguiente string

abcdefghijklmnñopqrstuvwxyz 0123456789º'¡`+´ç<,.-/*ª!"·$%&()=?¿^¨Ç;:_\|@#~€¬[]{}

cuando intento guardar cada caracter en líneas diferentes, se rompe:

Código
  1. function WriteFile($file, $data)
  2.    {
  3.        //file_put_contents($file, $data.PHP_EOL , FILE_APPEND | LOCK_EX);
  4.        $fp = fopen($file, "a+");
  5.        fwrite($fp, $data.PHP_EOL); //\r\n doesn't work neither
  6.        fclose($fp);
  7.    }
  8.  

Si la guardo sin el "newline" se guarda bien (todo en una línea), acá dejo como se guardan con el newline.

https://pastebin.com/5hM6W5qp

Alguno tiene idea de como solucionar ésto?

Desde ya muchas gracias, saludos!


En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: Escribir Archivo UTF8
« Respuesta #1 en: 6 Abril 2022, 21:48 pm »

Bueno, luego de mucho buscar, se me dió por pensar que debe estar tomando el byte en vez del string, lo cual es raro, porque los precompilados no manejan tipo de datos, pero bueno, era éso, al loopear una string hay que hacer algo feo como ésto

Código
  1. for ($i = 0; $i < strlen($chars); $i++)
  2. {
  3.    WriteFile("test.txt", mb_substr($chars, $i, 1));
  4. }
  5.  

Espero que le sirve a alguien xD

Saludos!


En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
apuromafo CLS


Desconectado Desconectado

Mensajes: 1.441



Ver Perfil WWW
Re: Escribir Archivo UTF8
« Respuesta #2 en: 7 Abril 2022, 02:49 am »

excelente ...

por otro lado, intentando entender el problema, es que según muchas fuentes
indican que los archivos antes de ser procesados deben ser convertidos.

https://stackoverflow.com/questions/4839402/how-can-i-write-a-file-in-utf-8-format


Saludos Cordiales
En línea

Apuromafo
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Escribir y leer un archivo
Programación Visual Basic
Debci 3 2,679 Último mensaje 21 Julio 2009, 18:02 pm
por Fabricio
Como escribir en un archivo xml <:s
Java
Debci 2 3,778 Último mensaje 18 Agosto 2009, 21:54 pm
por Debci
escribir strings en archivo (python)
Scripting
skalymut 1 3,872 Último mensaje 6 Febrero 2010, 15:55 pm
por ^Tifa^
Escribir archivo....
Programación Visual Basic
Petro_Boca 7 3,026 Último mensaje 24 Febrero 2010, 01:31 am
por agus0
Problema con BigDecimal (escribir archivo)
Java
Debci 3 6,521 Último mensaje 24 Abril 2010, 20:45 pm
por Debci
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines