pherank Posted March 8, 2008 Share Posted March 8, 2008 I've got some (admittedly) messy code that reads name/password entries from a textfile and displays them to the administrator: <?php $changed = false; $fp = fopen("clients.txt", "rb"); # do we want to delete a record if (isset($_GET['delid'])) { # remove deleted item from the array unset($fp[$_GET['delid']]); $changed = true; } if ($changed) { # now create new output file, writing in ini file format while (!feof($fp) ) { ksort($fp); # associative array arguments are keys not indexes foreach ($fp as $key=>$dataArray) { fwrite($fp, "[$key]\n"); foreach ($dataArray as $k => $v) { fwrite($fp, "$k=$v\n"); } fwrite($fp, "\n"); } fclose($fp); } } while (!feof($fp) ) { $line_of_text = fgets($fp); $parts = explode('=', $line_of_text); print $parts[0] . $parts[1]. " [<a href='$_SERVER[php_SELF]?delid=$key'>X<a>]<br />"; } fclose($fp); ?> What I'm trying to figure out is how to mark any particular item for delete and remove that array from the textfile. The textfile named clients.txt looks like this: frank blowfish sally tuna I can display the textfile entries to screen but I can't quite figure out how to tag the individual items and successfully delete those entries. Here's a Zip of the files I'm working with: http://www.tornedgedesign.com/_test/login/register.zip Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 $fp is not an array, it's a file handle for use in filesystem function calls on that file. If you have the text file in ini file format frank=blowfish sally=tuna peter=carp paul=shark mary=marlin then <?php $clients = parse_ini_file('clients.txt'); echo '<pre>', print_r($clients, true), '</pre>'; ?> gives this array clients = Array ( [frank] => blowfish [sally] => tuna [peter] => carp [paul] => shark [mary] => marlin ) Now you can unset ($clients['paul']); Quote Link to comment Share on other sites More sharing options...
pherank Posted March 8, 2008 Author Share Posted March 8, 2008 Your code prints out as: Array ( ) So I don't see any values. I'm not sure what the deal is. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.