Forum Moderators: coopster

Message Too Old, No Replies

determine line breaks used in files

explicitly detect line breaks / endings

         

phazei

2:09 am on Apr 17, 2009 (gmt 0)

10+ Year Member



I need to be able to figure out what type of line breaks a file is using (lin,win,mac).

I figure if I can just read the first couple lines in, I could easily do a preg_match for \r, \r\n, or \n.

I have auto_detect_line_endings enabled, and it works for fgetcsv, but I need to explicitly know what it ends in. I'm generating LOAD DATA INFILE LINES TERMINATED BY '?' for mysql.

I'm not sure how I can detect the line endings. PHP only lets me read line by line, or needs to load the entire file, and these files are multi-gig files so that's not an option.

Ideas?

Thanks

cameraman

3:32 pm on Apr 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a look at fread [php.net] (Filesystem [php.net] Functions). Getting your data that way should allow you to apply some regex.

phazei

5:16 am on Jun 15, 2009 (gmt 0)

10+ Year Member



Thanks :)

Just what I needed.