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 8073155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:14:57+00:00 2026-06-05T14:14:57+00:00

Im trying to read files with from the server. This works pretty well but

  • 0

Im trying to read files with from the server. This works pretty well but i got a problem:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
dignissim, magna sed egestas suscipit, tortor nunc lacinia felis, eget
tempus nunc neque non augue. Suspendisse ut turpis nulla. Suspendisse
eu nisi quis tortor porttitor elementum. Mauris id massa turpis.
Nullam scelerisque euismod sollicitudin.

Nam imperdiet lorem nec mi posuere laoreet. Pellentesque sed metus
eget quam pulvinar imperdiet ut et diam. Maecenas molestie magna vitae
metus pretium posuere. Aliquam erat volutpat. In ut libero nulla, sit
amet consequat lacus. Quisque ac lectus a libero venenatis placerat
sed ac metus. Aenean congue nunc non sapien vulputate tempus.

If i put a line break in the textfile it only reads the second paragraph.
What is the best way to fix this?

Here is my code:

$file = "./textfiles_tips/woningmarkt.txt";
if (file_exists($file))
{
    $f = fopen($file, "r");

    while ( $line = fgets($f) )
    {
        $data['text'] = $line;
    }
}
else
{
    echo "The file $filename does not exist";
}

$this->layout->buildPage('main/tips/woningmarkt', $data);
  • 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-06-05T14:14:59+00:00Added an answer on June 5, 2026 at 2:14 pm

    You overwrite $data['text'] every line. Use .= to append instead of overwriting.
    Before the loop use $data['text'] = ''; to initialize it to an empty string.

    $data['text'] = '';
    while ($line = fgets($f)) {
        $data['text'] .= $line;
    }
    

    However, you can do it even easier using file_get_contents. Replace the whole code from fopen until the loop with this:

    $data['text'] = file_get_contents($file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download files from ftp server with this code: using (System.IO.FileStream
I'm trying to read a txt file from a ftp server and I'm getting
I am trying to read multiple files in R from the working directory and
I'm trying to generate POJO's from mapping xml files. I read something about adding
I am trying to read a text file from raw folder, and it works
I'm trying to read a remote binary file (say, image) from internet like this:
I am trying to read an XML-file from another server. However the the company
I'm trying to read a file line by line, which works perfectly but I
So I'm trying to generate and save an Excel-file to the server. This works
I'm trying to read a file from a local filesystem. I do not have

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.