Anyway, I'm trying to learn the basics of using PHP with text files. I've always used MySQL databases, but for my current project a database would be considered overkill.
Ultimately, I'm trying to make a flatfile shoutbox but I'll make up an example of my code right now.
THE PHP CODE:
Code: Select all
<?php
$lines = file("test.txt");
krsort($lines);
foreach($lines as $data)
{
list($band,$song) = explode("||", $data);
echo "
$band ===> $song<br><br>
";
}
?>Code: Select all
Led Zeppelin||Stairway To Heaven
Van Halen||Jump
Aerosmith||Sweet Emotion
Rolling Stones||Paint It BlackCode: Select all
Rolling Stones ===> Paint It Black<br>
Aerosmith ===> Sweet Emotion<br>
Van Halen ===> Jump<br>
Led Zeppelin ===> Stairway To Heaven<br><br>I'm trying to restrict it to show only the 6 most current shouts instead of all of them. I'm hoping this will be an easy fix, but I know very little about working with text files. In case I haven't explained what I'm trying to do clearly enough, here's what it would be IF I was working with a Database instead.
Code: Select all
$result = mysql_query("select * from shoutbox order by id desc limit 6");Any and all help would be greatly appreciated. If you can, please try to explain it because my knowledge of text files is very limited. It took me 3 days just to figure out everything I posted here!
Thank you for your time and help.