Re: line breaks

From: Date: Tue, 25 Nov 2003 14:53:15 +0000
Subject: Re: line breaks
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-170890@lists.php.net to get a copy of this message
Rodney Green wrote:
John Nichel wrote:
Chances are, $buffer has the line break on it when you read it in from the text file. Try striping off whitespace before you write... while (!feof ($handle)) {
    $buffer = rtrim ( fgets($handle, 1000) );
    fwrite ($fhandle, "chown $buffer:html
http://www.php.net/manual/en/function.rtrim.php
Thanks John! That was the problem. Rod
Now that I stop and think about it a bit, rtrim() may hurt you here. Since you're using a fread to read the text file, it will read the bytes you tell it (1000), then move on to the next line of code. So if you have a line as such in your text file... ./command --this=that and the fread() reaches the byte limit on the whitespace after command, it's going to remove that, and you'll end up with.... ./command--this=that You can tell rtim() what characters to strip by doing... rtrim ( $foo, "\n" ); but I've seen rtrim() strip blank spaces even when this is done. A better way may be to change the way you're reading in the source file; instead of using a fread, you can use file(), which will put each line in an array element...This way, it won't stop reading in the middle of a line.... $fhandle = fopen ("/scripts/thescript.sh" , "a"); $handle = file ( "/scripts/mail_list.txt" ); for ( $i = 0; $i < sizeof ($handle); $i++ ) { $buffer = rtrim ( $handle[$i] ); fwrite ($fhandle, "chown $buffer:html /scripts/var/spool/mail/$buffer\n", 4096); } fclose ($fhandle); -- By-Tor.com It's all about the Rush http://www.by-tor.com

« previous php.general (#170890) next »