RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Ken Robinson

At 05:35 PM 12/27/2005, Wagner, Aaron wrote:

k, I didn't see you filehandle on the fwrite.
I didn't know that you could write to the same file your reading?

Interesting


Actually, I use the file() function to read the whole file into an 
array, so the file isn't open when you do the fopen() of the output 
file. That's how you can write to the same filename, at least on OS's 
that don't do file versions.  On OS's with file versions, like VMS, 
opening the same file name just creates a new version and the old 
file remains intact.


Ken 



-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
  "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Wagner, Aaron
k, I didn't see you filehandle on the fwrite.  
I didn't know that you could write to the same file your reading?

Interesting

 
Thanx
Aaron N Wagner
Monitoring Systems and Network Tools
CCO-Command Center Operations
804.515.6298
 

> -Original Message-
> From: Ken Robinson [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 5:05 PM
> To: users@httpd.apache.org
> Subject: RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File
> 
> Quoting "Wagner, Aaron" <[EMAIL PROTECTED]>:
> 
> > That's nice but it doesn't fix the blank lines it just 
> skips them in the
> > file parse.  I think he wants to clean the file.  If the 
> file gets big,
> > he could take a performance hit skipping multiple lines.
> 
> If you ran the script you would see that the output file doesn't have 
> the blank
> lines. You can easily make the output file the same as the 
> input file, so you
> end up with a cleaned file.
> 
> I wrote & tested the script before I posted it.
> 
> Ken
> 
> 
> -
> The official User-To-User support forum of the Apache HTTP 
> Server Project.
> See http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: [EMAIL PROTECTED]
>"   from the digest: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
   "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Boysenberry Payne

Try:

$string = file_get_contents( "test.text" );
$string = file_put_contents( "test.text", preg_replace( 
"/(\r\n|\r|\n)(\s)*(\r\n|\r|\n)/", "$1", $string ) );



Boysenberry

boysenberrys.com | habitatlife.com | selfgnosis.com

On Dec 27, 2005, at 3:16 PM, Christopher Deeley wrote:

Does anyone know how to use PHP to delete blank lines in a text file. 
I use a text file to store usernames and passwords but with adding and 
deleting users, blank lines appear which returns an undefined offset 
error when the 'verify user script' tries to read each line of the 
text file.

 
Thanks


-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
  "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Ken Robinson

Quoting "Wagner, Aaron" <[EMAIL PROTECTED]>:


That's nice but it doesn't fix the blank lines it just skips them in the
file parse.  I think he wants to clean the file.  If the file gets big,
he could take a performance hit skipping multiple lines.


If you ran the script you would see that the output file doesn't have 
the blank

lines. You can easily make the output file the same as the input file, so you
end up with a cleaned file.

I wrote & tested the script before I posted it.

Ken


-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
  "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Wagner, Aaron
That's nice but it doesn't fix the blank lines it just skips them in the
file parse.  I think he wants to clean the file.  If the file gets big,
he could take a performance hit skipping multiple lines.

 
Thanx
Aaron N Wagner
Monitoring Systems and Network Tools
CCO-Command Center Operations
804.515.6298
 

> -Original Message-
> From: Ken Robinson [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 4:54 PM
> To: users@httpd.apache.org
> Subject: Re: [EMAIL PROTECTED] Delete Blank Lines In A Text File
> 
> Quoting Christopher Deeley <[EMAIL PROTECTED]>:
> 
> > Does anyone know how to use PHP to delete blank lines in a 
> text file. I use
> > a text file to store usernames and passwords but with 
> adding and deleting
> > users, blank lines appear which returns an undefined offset 
> error when the
> > 'verify user script' tries to read each line of the text file.
> 
> Here's a short script:
> $input = file('your_input_file.here'); // read file into 
> the array $input
> $fp = fopen('your_output_file.here');
> foreach ($input as $line)
> if (trim($line) != '') fwrite($line);  // if the line 
> isn't blank write
> it out
> fclose($fp);
>?>
> 
> 
> Ken
> 
> 
> -
> The official User-To-User support forum of the Apache HTTP 
> Server Project.
> See http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: [EMAIL PROTECTED]
>"   from the digest: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
   "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Ken Robinson

Quoting Christopher Deeley <[EMAIL PROTECTED]>:


Does anyone know how to use PHP to delete blank lines in a text file. I use
a text file to store usernames and passwords but with adding and deleting
users, blank lines appear which returns an undefined offset error when the
'verify user script' tries to read each line of the text file.


Here's a short script:
  


Ken


-
The official User-To-User support forum of the Apache HTTP Server Project.
See http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: [EMAIL PROTECTED]
  "   from the digest: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [EMAIL PROTECTED] Delete Blank Lines In A Text File

2005-12-27 Thread Wagner, Aaron



preg_replace($pattern, $replacement, 
$string); 

 
preg_replace("/\n\r *\n\r/","\n\r", 
$string )
 
\n\r *\n\r - for a windowz maching and they may be in 
the wrong order.
 
Your basically replacing all double linefeeds with a 
single linefeed.
Replace the \n\r with whatever your OS uses as a 
linefeed.
 
 


Thanx
Aaron N 
Wagner
Monitoring Systems and Network 
Tools
CCO-Command Center Operations
804.515.6298
 

  
  
  From: Christopher Deeley 
  [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 27, 2005 
  4:17 PMTo: users@httpd.apache.orgSubject: [EMAIL PROTECTED] 
  Delete Blank Lines In A Text File
  
  Does anyone know how to use PHP to delete blank lines in a text file. I 
  use a text file to store usernames and passwords but with adding and deleting 
  users, blank lines appear which returns an undefined offset error when the 
  'verify user script' tries to read each line of the text file. 
   
  Thanks