Page 1 of 1

Reading a txt file and echo'ing a line

Posted: Mon Oct 11, 2010 10:38 am
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

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

Posted: Mon Oct 11, 2010 10:44 am
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?