PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ages ago my mates and I setup a three word thread project to our website. Over time we added different variations to it on different pages, but decided to have the first one as the main one.
So the main page shows the data.txt (words submitted to data.txt via writetofile) but we wanna change it so that the main page shows the last few lines of all our other thread can this be done easily?
Below is the bit in our php file that echos the data.txt file (if its any help)
<?php
$file_loc = "data.txt";
$lines = file($file_loc);
if(!$lines)
{
echo "<p>Error: Unable to open $file_loc.</p>";
}
else
{
/*
Change 10 and 4 below to get what you need
*/
for ($i=10; $i<=count($lines)-4; $i++)
{
echo $lines[$i];
}
}
?>
That method someone gave you was half there but you need to loop still...
But unfortunately I've had a look at the data.txt file and its all on one line! So it dont show unless I change both values to zero. Even tried it on another txt file where all words are separated by <br> but still no luck!
So should I be looking at a character count (show for example last 50 characters) to get round it. But then I suppose theres always going to be occasions where words cutoff half way through.
How do I now change it so it would only return the words in between the last two <br>
This is because one of the threads is a quote one so each quote has <br> at the end, so if it only returns words between the last two <br> is ensures that a complete sentence is shown.