Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

299
Vistas
PHP: Write to file, and starting where it left off

I'm very unfamiliar with PHP...

<?php
    $myfile = fopen("emaillist.txt", "w");
    $newemail = "email1\n";
    fwrite($myfile, $newemail);
    $newemail = "email2\n";
    fwrite($myfile, $newemail);
    fclose($myfile);
?>

The code is to create a database of emails. When going to emaillist.txt, the output is:

email1
email2

The output will stay like that, even if I run the php file a new line. My desired output is to for example run it twice, and get:

email1
email2
email1
email2

I'm aware storing emails in .txt files isn't smart, but this isn't for real world use.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You are using the w mode of fopen(). To place the file pointer at the end, use a or a+.

over 4 years ago · Santiago Trujillo Denunciar

0

It turns out I had to do fopen("emaillist.txt", "a");instead of fopen("emaillist.txt", "w");because a appends to the file, while w just writes to it.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda