Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!