-entropyman Posted July 23, 2008 Share Posted July 23, 2008 Hello, I was just wondering if it would be possible to read a file backwards. For example I am reading a file using file_get_contents and outputting all the line matches that contain the results. Is there a way to read the file backwards, ie the result that would be return last normally would now return first? Or order the results as such? Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/116118-solved-reading-backwards/ Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 if you're doing it line by line you could use file() instead of file_get_contents. That will read your entire file and put it into an array (one line per element) instead of a giant string like what file_get_contents does. Then you can array_reverse the array and loop through it. Link to comment https://forums.phpfreaks.com/topic/116118-solved-reading-backwards/#findComment-597119 Share on other sites More sharing options...
tibberous Posted July 23, 2008 Share Posted July 23, 2008 If you wanted to do it literally, you could use strrev, which is perhaps the most useless function in the whole core. Link to comment https://forums.phpfreaks.com/topic/116118-solved-reading-backwards/#findComment-597168 Share on other sites More sharing options...
-entropyman Posted July 23, 2008 Author Share Posted July 23, 2008 worked perfectly, thank you crayon Link to comment https://forums.phpfreaks.com/topic/116118-solved-reading-backwards/#findComment-597290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.