PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Fri Jun 18, 2004 11:31 am
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"
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Fri Jun 18, 2004 11:34 am
Try using \n instead of \r. Should work, but no to sure on that!
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Fri Jun 18, 2004 12:49 pm
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
kendall
Forum Regular
Posts: 852 Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:
Post
by kendall » Fri Jun 18, 2004 12:56 pm
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){ ?>
<tr>
<td width="30%" align="center" valign="middle" id="name"><?php echo $brand_name; ?></td>
<td width="70%"><input name="brand_nameї]" type="checkbox" id="brand_nameї]" value="<?php echo $brand_name; ?>" checked></td>
</tr>
<?php } ?>
<tr>
<td> </td>
i get the extra lines im reading back the file using file() which reads line by line