Splitting files in to an array by 'end of line'.

Hi,

Need to split a file by the 'end of each line' in to an array.

Currently, if I have EOF at the end of each line I could do it like this:

$logfile = ("LOGS_TMP.TXT");
$handle = fopen($logfile, "r");
$contents = fread($handle, filesize($logfile));

$list = split ('EOF', $contents);

But I don't want to manually add EOF to every line.

Can't use:

$list = file( $logfile,'');

as the results that I am bringing in mess it up with 'Unterminated String Constant'.

Question 1 -

What can I put in place of EOF so that it splits by each line.

Question 2 -

If I can't do Q1, can I add EOF to the end of each file (Without saving it).

Cheers,
Jas.


jramsdenAsked:
Who is Participating?
 
Diablo84Commented:
If you add EOF to the end of each line and then split by that i do not see that the results would be any different from just splitting by \n in the first place, if the body spans across multple lines then you may have to take a slightly different approach. Could i possibly see a sample entry from the file if this is the case.
0
 
Diablo84Commented:
You would use

\n

or if its in windows format

\r\n

and dont use split use explode, eg

explode("\n",$contents);
0
 
Diablo84Commented:
Also instead of fopen and fread you might want to just use file_get_contents
http://us2.php.net/manual/en/function.file-get-contents.php
0
 
jramsdenAuthor Commented:
This does work, but unfortunatly no with the file I'm bringing in.
It's a series of emails split by DATE, TIME, EMAIL, SUBJECT and BODY.
Because of the amount of text in the BODY section, it's not completing the task as specified.

Can you answer Q2 (Adding EOF to the end of each line).

Cheers,
Jason.
0
 
TheUnkindCommented:
if you want to get it line by line use

$list=file($string);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.