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!
Is there a way to write to the top of a text file rather than to the bottom. I need to display my latest post at the top of the page. Currently it display this last.
Also i have a paging system in place which works, although it has a small downfall.
It creates page links but unfortuntely doesnt truncate them to 1 2 3....9 10 11 for example and rather display then as 1 2 3 4 5 6 and so on.
i created a sorting array. which loads via two php pages. data.php loading as is posted in the text file and data2.php loads information from the bottom up. Unfortuantely the results are too unpredicatable.
Do you know a way of writing to the top of a text file??
or possibly script which i may use instead of my own
typically, it's done by writing the new data to a temporary file, copying in all old data, deleting the old file, and renaming the temporary to the original name.
You will have to be VERY careful of concurrent changes to the file because of this operation. It is often, not so good to prepend to a file because of the actions required. Even reading in the original file, prepending to that string and writing out can have memory problems. This is why data is often appended and sorted on the fly.
i see, thats definately something i dont want to do.
So a reverse array seems the only way to go. Are there any tutorials i cud use for this / code i can view and modified?