Array problem

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

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Array problem

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you add a "\n" to the end of each line write to force a new line in the file?
Post Reply