Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:38:14+00:00 2026-05-24T15:38:14+00:00

To start out with, I basically have a function that opens up a text

  • 0

To start out with, I basically have a function that opens up a text file, grabs the first line, removes it from the file, and saves the file with the remainder. Everything is working fine except when I come to use the return statement to return the line retrieved. Using the return statement, for some reason it clears the file; removing the return statement, the function does what it’s supposed to. I’m debating whether this is a PHP bug or if there’s something hidden here that I’m not seeing. Parts of the code is listed below, any help will be immensely appreciated.

Thanks!

    $nlines = array();

    $lines  = file(CACHE_PATH."/test.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    $link  = $lines[0];

    $lcount = count($lines)-1;
    for($i=1; $i < $lcount; $i++)
    {
        $nlines[] = $lines[$i];
    }

    $file  = fopen(CACHE_PATH."/test.txt", 'w');

    for($i=0; $i <= $lcount; $i++)
    {
        fwrite($file, $nlines[$i]);
    }

    fclose($file);

    return $link;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:38:14+00:00Added an answer on May 24, 2026 at 3:38 pm

    The code seems aright to me. However here is a simplified version. Its untested though:

    function something(){
    
        $lines  = file(CACHE_PATH."/test.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $link  = $lines[0];
        unset($lines[0]);
    
        $file  = fopen(CACHE_PATH."/test.txt", 'w');
        fwrite($file, implode("\n" , $lines) );
        fclose($file);
    
        return $link;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start out by saying that I'm not a JavaScript developer so this
I'll start out by giving you the code I'm working on so that you
I'm trying to start out with LinqtoXml. I have added (I think) the right
I'm working on early designs for an application that needs to start out small
Need some help assigning a mouseover event to display some icons that start out
I have written a function which basically hides the complication of using the pySnmp
I'm using the wp_list_bookmarks() function in wordpress to get links that have been added
Sheet1 Sheet2 Above i have two images link that i have captured from my
What is a strong iPhone framework to start out developing with, besides the SDK
Often when beginning a new project, I start out with what I believe to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.