Re: [PHP] Re: file() and macintosh line break

2002-05-03 Thread Josh Valerie McCormack

I was having a tough time with a Mac file uploaded and squeezed into one 
line. My friend Shawn helped me write the following which cleans it up. 
Remove the echo statement to just change it and not see the change. 
Also, avoid trying to fix the file, make a new one, if you can.

Hope this helps.

Josh


  1 ?
  2 $data_file = data.csv;
  3 $newdatafile = new_data.csv;
  4
  5 $file=fopen($data_file, r);
  6 $newfile = fopen($newdatafile,w);
  7
  8 $filecontents = fread($file,filesize($data_file));
  9 echo $filecontents;
 10 echo brbr;
 11 $newfilecontents = preg_replace((\r\n|\n|\r),\n,$filecontents);
 12
 13 echo nl2br($newfilecontents);
 14
 15 fwrite($newfile,$newfilecontents);
 16 fclose($file);
 17 fclose($newfile);
 18 ?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: file() and macintosh line break

2002-05-01 Thread Yasuo Ohgaki

Rodrigo Peres wrote:
 Hi list,
 
 I'm in a problem that is driving me crazy!!! I want open a file and puts 
 each line into an array, but this files was created in macintosh!! so 
 the file() can't recognize the end line and only outputs 1 element in 
 array!! How can I solve it. I tried to fread() the file and 
 eregi_replace the line breaks, it worked, but now I don't know how to 
 use this to create the array!
 

You can use split().
I think Mac linebreak is better to be recognized by PHP...

--
Yasuo Ohgaki




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: file() and macintosh line break

2002-05-01 Thread eat pasta type fasta

just a thought, mac line break is \r

you can open and save it as unix that should get rid of the weird 
problem, unless you need it to work for numerous uncotrolled file flow, 
then replacing \r might work with a FOR loop. You might have to fwrite 
to a new file there \r will become \n and have that be processed as a 
continuum of the same script.

R

Rodrigo Peres wrote:
 Hi list,
 
 I'm in a problem that is driving me crazy!!! I want open a file and puts 
 each line into an array, but this files was created in macintosh!! so 
 the file() can't recognize the end line and only outputs 1 element in 
 array!! How can I solve it. I tried to fread() the file and 
 eregi_replace the line breaks, it worked, but now I don't know how to 
 use this to create the array!
 

You can use split().
I think Mac linebreak is better to be recognized by PHP...

--
Yasuo Ohgaki




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--__-__-__
eat pasta
type fasta


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: file() and macintosh line break

2002-05-01 Thread Philip Olson


Here's a bug report:

  file() - incorrect behavior (line endings ignored) on 
   files with Mac EOLN (CR)

   http://bugs.php.net/bug.php?id=16521

Maybe some kind soul will fix this before PHP 4.3.0 :)

  http://cvs.php.net

Regards,
Philip Olson


On Thu, 2 May 2002, eat pasta type fasta wrote:

 just a thought, mac line break is \r
 
 you can open and save it as unix that should get rid of the weird 
 problem, unless you need it to work for numerous uncotrolled file flow, 
 then replacing \r might work with a FOR loop. You might have to fwrite 
 to a new file there \r will become \n and have that be processed as a 
 continuum of the same script.
 
 R
 
 Rodrigo Peres wrote:
  Hi list,
  
  I'm in a problem that is driving me crazy!!! I want open a file and puts 
  each line into an array, but this files was created in macintosh!! so 
  the file() can't recognize the end line and only outputs 1 element in 
  array!! How can I solve it. I tried to fread() the file and 
  eregi_replace the line breaks, it worked, but now I don't know how to 
  use this to create the array!
  
 
 You can use split().
 I think Mac linebreak is better to be recognized by PHP...
 
 --
 Yasuo Ohgaki
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 --__-__-__
 eat pasta
 type fasta
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: file() and macintosh line break

2002-05-01 Thread Justin French

I agree -- if this is a once-off problem, then just open the file in a
Windows or Unix machine, re-save it, and the problem should be solved.

If the Mac user has BBEdit or BBEdit lite, one of the options they have is
to save in Unix and Windows format, which fixes the problem simply.


Of course if this is an ongoing thing, or if you don't have control over the
mac user, or the opportunity to convert the files as above, then there seem
to be some other ideas floating around this thread :)


Justin French


on 02/05/02 2:49 PM, eat pasta type fasta ([EMAIL PROTECTED]) wrote:

 just a thought, mac line break is \r
 
 you can open and save it as unix that should get rid of the weird
 problem, unless you need it to work for numerous uncotrolled file flow,
 then replacing \r might work with a FOR loop. You might have to fwrite
 to a new file there \r will become \n and have that be processed as a
 continuum of the same script.
 
 R
 
 Rodrigo Peres wrote:
 Hi list,
 
 I'm in a problem that is driving me crazy!!! I want open a file and puts
 each line into an array, but this files was created in macintosh!! so
 the file() can't recognize the end line and only outputs 1 element in
 array!! How can I solve it. I tried to fread() the file and
 eregi_replace the line breaks, it worked, but now I don't know how to
 use this to create the array!
 
 
 You can use split().
 I think Mac linebreak is better to be recognized by PHP...
 
 --
 Yasuo Ohgaki
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 --__-__-__
 eat pasta
 type fasta
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php