Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda