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

x
?
Solved

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

Posted on 2004-10-27
7
Medium Priority
?
235 Views
Last Modified: 2006-11-17
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.


0
Comment
Question by:jramsden
[X]
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
7 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 12421942
You would use

\n

or if its in windows format

\r\n

and dont use split use explode, eg

explode("\n",$contents);
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12421964
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
 

Author Comment

by:jramsden
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).

Cheers,
Jason.
0
 
LVL 27

Accepted Solution

by:
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.
0
 
LVL 2

Expert Comment

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

$list=file($string);
0

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