Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Reverse List
I am writing an extension where people post interesting links for all to see, it seems to be working OK.
My problem is that new links are added to the bottom of the list (it uses a flat text file) so the old links are always at the top.
Is there a way (PHP) that I can reverse the entries so the new ones are at the top?
This is my current code (no laughing please)...
My problem is that new links are added to the bottom of the list (it uses a flat text file) so the old links are always at the top.
Is there a way (PHP) that I can reverse the entries so the new ones are at the top?
This is my current code (no laughing please)...
$link_file="links.txt";
$write = "<a href=\"$url\">$name</a> | $desc<br>\n";
$fp=fopen($link_file, "a");
fwrite($fp, $write);
fclose($fp);
Posted: Tuesday, 10 April 2007 at 12:17PM
0
This discussion has been closed.
Comments
This method does it more elegantly.
Test it here if you like.
Posted: Tuesday, 10 April 2007 at 1:59PM
The method Jim suggested worked first time with no modification, I'm happy.
Posted: Tuesday, 10 April 2007 at 4:44PM
echo implode('', array_reverse(file('links.txt')));
$File = 'links.txt'; $Lines = file($File); if (is_array($Lines)) { $ReversedLines = array_reverse($Lines); $ReversedLines[] = "my new value"; $Lines = array_reverse($ReversedLines); $ConcatentatedLines = implode('', $Lines); $FilePointer = fopen($File, "a"); fwrite($FilePointer, $ConcatenatedLines); fclose($FilePointer); }
That's untested code ... but it's something along those lines...