Reading a txt file and echo'ing a line

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!

Moderator: General Moderators

Post Reply
Jamescgr
Forum Newbie
Posts: 3
Joined: Wed Oct 06, 2010 1:26 pm

Reading a txt file and echo'ing a line

Post by Jamescgr »

Dear Forum,

I have a script that is out-putting a text file, I want to parse the text file and then echo one of the lines to the browser

The file lives in '/mnt/app/out/php/file.txt'

The file.txt is in the following format: -
-------------------------------------------------------------------------------------------------------------

Welcome to World Agent 1.00

password:


WTA> KHATIB,Khatib,N,EN,28,0,0,0,,N,60,,,N,0,,0,,,,STTDM,,,0,0,0,,,0,,0
WTA> Goodby

-------------------------------------------------------------------------------------------------------------
So first line/line 0 is blank, and there are 9 lines altogether
I want to echo line 6 to the browser (with first line being 0)
Even better would be if I could just echo part of line - Khatib,N,EN,28,

Could anyone please let me know what function could achieve this and possibly an example incorporating the above?

I have tried file() and explode but I am not getting very good results.

Many thanks
Jamescgr
Forum Newbie
Posts: 3
Joined: Wed Oct 06, 2010 1:26 pm

Re: Reading a txt file and echo'ing a line

Post by Jamescgr »

I have actually acheived echoing the line in the file back using -

$lines = file('/mnt/app/out/php/file.txt'); echo $lines[6];

But this returns - WTA> KHATIB,A Faez Khatib,Y,EN,28,0,0,0,,N,60,CARD,CARDW,N,0,CARD,0,,,,CARD,,,0,0,0,,,0,,0

Ideally I want to trim this to the results as mentioned above, any ideas please?
Post Reply