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);
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.However, you can do it even easier using
file_get_contents. Replace the whole code fromfopenuntil the loop with this: