Hello Tom, Thursday, February 27, 2003, 7:39:52 PM, you wrote:
TR> Hi, TR> Friday, February 28, 2003, 12:20:38 PM, you wrote: RK>> I really need somebody to help me with this I am totally lost on what RK>> to do RK>> I need a way to read the following text file and add to or delete from RK>> or change the data. RK>> I have been able to move it all into an array using this code RK>> $groups= file("group"); RK>> for ($i=0; $i<$number_in_group; $i++){ RK>> $groups[0]; RK>> $groups[3]; <-- this is the part of the array that I need to change RK>> } RK>> But I can not figure out how to search the array and delete from or add RK>> to the array at a given point. I would like to say add another user to RK>> the end of site6 or delete a user from site3. RK>> Could somebody give me a hand here. I have read the manual for arrays RK>> and still can't figure it out. RK>> site1:x:503:tester1 RK>> site2:x:504:tester2,tester2a RK>> site3:x:505:tester3,tester3a,tester3b RK>> site4:x:506:tester4 RK>> site5:x:507:tester5,tester5a,tester5b RK>> site6:x:508:tester6 RK>> site7:x:509:tester7,tester7a,tester7b RK>> -- RK>> Best regards, RK>> Richard mailto:[EMAIL PROTECTED] TR> your groups array will look like this TR> groups[0] = site1:x:503:tester1 TR> groups[1] = site2:x:504:tester2,tester2a TR> so loop through the array TR> $x = 0; TR> while(list($key,$val) = each($groups)){ TR> //you need split the array values like this TR> list($name,$pass,$gid,$user_list) = split (":", $groups[$x]); TR> //see if we have the right one TR> if($name = $wanted_name){ //site6 TR> //then split the usernames into a sub array TR> $users = explode(',',$userlist); TR> // to add TR> $users[] = $newuser; TR> // to delete TR> unset($users[3]) TR> // now add it back TR> $userlist = implode(',',$users) TR> $list = $name.':'.$pass.':'.$gid.':'.$userlist; TR> $groups[$x] = $list; TR> } TR> $x++; TR> //here you could fputs to a temp file then copy to the original TR> // after finished TR> } TR> Then write groups back to disk TR> -- TR> regards, TR> Tom Thanks for the help!! I still can't seam to get it to add a new user at the end of a line of the selected site name. Also how do I use the unset($users[3]) do I first have to determine what number the one I what to delete is. Here is what I have so far $newuser="tester45"; $wanted_name="site7"; $groups= file("group"); $x = 0; while(list($key,$val) = each($groups)){ //you need split the array values like this list($name,$pass,$gid,$user_list) = split (":", $groups[$x]); //see if we have the right one if($name = $wanted_name){ //site6 //then split the usernames into a sub array $users = explode(',',$userlist); // to add $users[] = $newuser; // to delete //unset($users[3]); // now add it back $userlist = implode(',',$users); $list = $name.':'.$pass.':'.$gid.':'.$userlist; $groups[$x] = $list; } $x++; $handle = fopen("group2", 'a'); fputs($handle, $groups[$x]); //here you could fputs to a temp file then copy to the original // after finished } //Then write groups back to disk -- Best regards, Richard mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php