Page 1 of 1

file fwrite() using "\r" and "\n" in str

Posted: Fri Jun 18, 2004 11:31 am
by kendall
Hello,

The following code is being used to write $_POST array variable to a text file.

Code: Select all

// read files function
function FILE_ACTIONS($file,$action,$string=false){
	if($action == 'r'){
		$content = file($file);
	}elseif($action == 'w' || $action == 'a'){
		$fp = fopen($file,$action);
		if(fwrite($fp,$string)){
			fclose($fp);
			return true;
		}else{
			fclose($fp);
			return false;
		}
	}
	if($content)
		return $content;
	else false;
}

$brands = $_POSTї'brand_name'];
	if(count($brands)>0){ // if array 
		$brands = join("\r",$brands);
	}else{ $brands = "ANY";}

FILE_ACTIONS($file,$action = "w",$string = $brands);
However I get the following ouput
NIKE

ADIDAS

REEBOK

FILAS

K-SWISS
What gives with the extra "new line"

Posted: Fri Jun 18, 2004 11:34 am
by Joe
Try using \n instead of \r. Should work, but no to sure on that!

Posted: Fri Jun 18, 2004 12:49 pm
by kendall
Joe,

funny thing... i am trying it out using both "\r" and "\n"

in Netscape it works fine
in IE it shows the extra line....

WTF is that all about...

Kendall

Posted: Fri Jun 18, 2004 12:56 pm
by kendall
Ok,

I have been going over the code and heres what

i have substituted the \n for \r and it works

but for some reason in IE

when i

Code: Select all

<?php foreach($brands as $brand_name)&#123; ?>
          <tr> 
            <td width="30%" align="center" valign="middle" id="name"><?php echo $brand_name; ?></td>
            <td width="70%"><input name="brand_name&#1111;]" type="checkbox" id="brand_name&#1111;]" value="<?php echo $brand_name; ?>" checked></td>
          </tr>
          <?php &#125; ?>
          <tr> 
            <td>&nbsp;</td>
i get the extra lines im reading back the file using file() which reads line by line