Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 17 Dec 2001, 16:02
Mincer's Avatar
Mincer Mincer is offline
 
Join Date: Nov 2001
Couple o php questions

1) Is there an easy way to strip "'s from a text file using php?

It's not really feasible to do a s/r using a text editor as the files will be uploaded by a user and actioned directly rather than them passing through my control first.


2) How can I read a line at a time from a csv file before exploding it?

Say grab all characters into a string until \n and then process, then repeat in a loop until EOF

(I could do this in c++ - albeit a bit rusty now - but not really sure in php)

Any solutions greatly appreciated.

Matt.

--------------------------

If there's no way of easily reading the file a line at a time, is it a really bad idea to read a 1000+ line file in to an array in one go, and then exploding it into lines on \n, and then exploding each line at a time on the delimiter?

Lastly, if I do this, is this a good way of exploding a line at a time until EOF??


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I know that this will work ok for small files, but what would be a cut-off for 'small file' ??
__________________
Team Phoenix Rising
Distributed Computing

- ph33r my 1337 r3\/3r3 @\/47@r -
Reply With Quote
  #2  
Old 17 Dec 2001, 16:17
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
1) try this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

2) try this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

PHP DOCS: fgets(), fopen(), feof(), str_replace
Reply With Quote
  #3  
Old 17 Dec 2001, 16:37
Mincer's Avatar
Mincer Mincer is offline
 
Join Date: Nov 2001
Thanks for the quick response.

The first question, I needed to replace the quotation char " with nothing. I guess the principal is the same though. Can I just use \" ??


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

EDIT: Yes it is.

-----------------

Secondly, just so I understand correctly... (always a bonus in my case )... fgets() reads one line up to endline?? (nix or win or both??)

Thanks.
__________________
Team Phoenix Rising
Distributed Computing

- ph33r my 1337 r3\/3r3 @\/47@r -

Last edited by Mincer : 17 Dec 2001 at 16:40.
Reply With Quote
  #4  
Old 17 Dec 2001, 16:59
Mincer's Avatar
Mincer Mincer is offline
 
Join Date: Nov 2001
In case anyone cares....

I added:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

To stop it outputting garbage if there are empty lines at the end of the file. (in my case empty lines will not occur in the file up till then).
__________________
Team Phoenix Rising
Distributed Computing

- ph33r my 1337 r3\/3r3 @\/47@r -
Reply With Quote
  #5  
Old 18 Dec 2001, 04:20
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
fgets() will read up to the number of bytes you specify, until it reads a EOL, or until EOF (which ever comes first). PHP is wise to the win/unix differences, and will watch for \n on unix and \r\n on win for EOL.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 07:24.

Layout Options | Width: Wide Color: