Re: Re: help with end of line charater

From: Date: Fri, 30 Jan 2009 17:58:32 +0000
Subject: Re: Re: help with end of line charater
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-287431@lists.php.net to get a copy of this message
Shawn McKenzie wrote:
This may be best handled in your sorting code. What does it look like?
yeah just a second ago a big lightbulb went off in my head and i fixed my code to add a \r\n on saving, and strip it on viewing. I sort on viewing, not sort on saving. The viewing code looks like: $biglist = ""; $filename = "/usr/local/majordomo/lists/".$edit; $fp = fopen($filename, "r") or die ("Couldn't open $filename"); if ($fp)
       {
       while (!feof($fp))
               {
               $thedata = fgets($fp);
               $buildingvar[] = $thedata;
               }
                       sort($buildingvar);
                       foreach ($buildingvar as $key => $val)
                               {
                                if ($val != "\r\n")  //gets rid of empty whitespace lines
                                       {
                                       $biglist .= "$val";
                                       }
                               }
       }
//$biglist gets echo'd into a textarea box below. but now right before it is saved, i'll add a new line $list .="\r\n"; $fp = fopen($filename, "w") or die ("Couldn't open $filename"); if ($fp)
       {
       fwrite($fp, $list);
       echo "
       <head><title>Saving Page</title>
       <link rel=stylesheet href=/maillist.css type=\"text/css\">
       </head>
       Your mailing list has been updated.";
       }
fclose($fp); so that upon viewing, if they didn't press enter, a \r\n will be added, and even if they did add press enter on the last line, it'll be stripped out upon viewing the list of email addresses.

« previous php.general (#287431) next »