Page 1 of 1

Array problem

Posted: Tue Feb 06, 2007 1:46 pm
by spacebiscuit
Hi guys,

I have been banging my head up the wall with this bit of code which really should work but doesn't:

Code: Select all

if(false !== ($index = array_search($email,$list))) {

                  unset($list[$index]);  // unset an array index and re-index the array
                  $temp=array_values($list);
                  $list=$temp;
                  
                  $handle2=fopen("email_list2.txt","x+"); // create and prepare a file to be written to

                  foreach($list as $val){ // write the array to the file
                      fwrite($handle2, $val, strlen($val));
                                        }

                  fclose($handle2); 

                  unlink("email_list.txt");

                  rename("email_list2.txt","email_list.txt");


                       
                                                                 }
All works fine except that the array contents are written on a single line, I want a line for each array index and the file name is not renamed and deleted.

Any help would be appreciated.

Thanks,

Rob.

Posted: Tue Feb 06, 2007 2:44 pm
by RobertGonzalez
Can you add a "\n" to the end of each line write to force a new line in the file?