Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » PHP




 Page 1 of 1 [ 3 posts ] 



Author Message
 Post subject: could I read a multiline var like a multi line file?
 Post Posted: Thu Nov 19, 2009 7:13 am 
Offline

Joined: Sat Feb 21, 2009 1:04 pm
Posts: 47
I m havin a routine dat calls a func which returns a
multiline string. (a tab delimited text db, essentially).

I was been wonderin if der was a way 2 read dat var line by line in a
for each loop as if it were a file, widout first writin it 2 disk nd
callin da file() function nd widout turnin it to first in 2 a \
huge array.

Thanks 4 ne tips and hints


Top 
 Post subject: Re: could I read a multiline var like a multi line file?
 Post Posted: Thu Nov 19, 2009 7:13 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
You could explode() on newlines (or whatever line delimeter) which returns an array

Code:
   1. $csvdatalines = explode(PHP_EOL, $csvdata); //split on newlines
   2. 
   3. foreach ($csvdatalines as $row) {
   4.    // process
   5. }


Top 
 Post subject: Re: could I read a multiline var like a multi line file?
 Post Posted: Thu Nov 19, 2009 7:14 am 
Offline

Joined: Sat Feb 21, 2009 1:05 pm
Posts: 66
The array wun need dat much more memory than da originals single
string. So unless u have LOTS of columns per line or very long values,\
12000 rows should be rathr insignificant 4 ne decent webserver.

_________________
If your wife wants to learn to drive, don't stand in her way.


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 3 posts ] 




Board index » Server Side Development » PHP


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron