Jump to content

Using strstr() to find a line, and fwrite() to delete it?


bloodgoat

Recommended Posts

Or something along those lines... how would I go about this?

 

Say this is my array:

<?php
$array = array();
$array[] = array("value 1a", "value 2a", "value 3a"); // [0]
$array[] = array("value 1b", "value 2b", "value 3b"); // [1]
$array[] = array("value 1c", "value 2c", "value 3c"); // [2]
?>

Now let's say I would like to clear $array[1] from the file. How would I go about doing this? foreach() or for() loop? Or what...

~

 

Just looking around... would preg_replace or something be a better option? Or... I really have no idea how to approach this. I mean, for my real application, I have:

 

USERS.PHP

<?php

$users = array();
$users[] = array("user 1", "pass 1", "2");
$users[] = array("user 2", "pass 2", "2");
$users[] = array("user 3", "pass 3", "3");
// "username", "password", "permissions"

?>

 

Then I have a MANAGE_USERS.PHP file which I'm trying to work with right now to implement a "delete user" system.

Base URL is "?action=manage_users" and for the deleting function, I want it to link like "?action=manage_users&delete=WhateverUserWasSelected". This is all I have so far:

<?php

include("./users.php");

if(!isset($_GET['delete'])){
$content .= "<table width=\"900\" cellpadding=\"4\" cellspacing=\"0\">\n";
foreach($users as $user_list){
	$content .="	<tr>
		<td width=\"50%\" class=\"apleft\">".$user_list[0]." (".$user_list[2].")</td>
		<td width=\"50%\" class=\"apright\"><a href=\"?action=manage_users&delete=".$user_list[0]."\">Delete</a></td>
	</tr>\n";
}
$content .= "	<tr>\n		<td class=\"apfoot\" colspan=\"2\"> </td>\n	</tr>\n</table>";
}

?>

So pretty much, just the table showing the full userlist, and an option to delete. But I don't know how to approach actually making the delete feature work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.