[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


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

Posted on 2004-10-27
Medium Priority
Last Modified: 2006-11-17

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).


Question by:jramsden
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 27

Expert Comment

ID: 12421942
You would use


or if its in windows format


and dont use split use explode, eg

LVL 27

Expert Comment

ID: 12421964
Also instead of fopen and fread you might want to just use file_get_contents

Author Comment

ID: 12422160
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).

LVL 27

Accepted Solution

Diablo84 earned 500 total points
ID: 12422302
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.

Expert Comment

ID: 12430002
if you want to get it line by line use


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question