![]() |
Read Text File in Reverse
Hello all,
I have a text file that contains enteries like so: Code:
date||name||title||descriptionI can read it backwards using: Code:
$file = array_reverse( file( 'u4g.txt' ) );but cannot figure out how EXPLODE each line in a foreach. Why can't I do something like this: Code:
$file = array_reverse( file( 'u4g.txt' ) );Code:
$line_of_text = fgets($fp);Thanks! |
So I used this:
Quote:
|
Quote:
description2, title2, name2, date2 description, title, name, date Correct? |
you need to declare $parts as an array first before assigning an array value to it. like this:
PHP Code:
|
I know you should do that, but is it mandatory?
|
Quote:
$parts from the call to explode just like giving it a fixed value (like 1.3 or 'fixed value'). There's no need to create the variable beforehand. |
Quote:
I don't want to read each line in reverse, I want to read the entire text file lines in reverse, but keep the lines data in the correct order. ie take this in the text file: Code:
data||email||name||descriptionCode:
data2||email2||name2||description2 |
I ran the code:
PHP Code:
Code:
data1||email1||name1||description1Code:
data6||email6||name6||description6It's been a while since I worked with files |
Thanks Tony,
I am not sure why the first code snippet wouldn't work, but that one did. It runs it correctly too. So just starting with: Code:
$file = array_reverse( file( 'u4g.txt' ) );GREAT! Thanks a bunch! |
No problem, it's weird that it didn't work since is the same procedures. But it worked, that is always a relief.
|
| All times are GMT. The time now is 06:29 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0