0

Hey. i was wondering howto delete a single line from a FFD

on the server that i currently have, it is not possible to use a mySQL database and I'd rather keep it a FDD

I have tried too no avail.

Here is my current code

<?php

$file = fopen('clients.txt','r');
$id = $_REQUEST['id'];

for ($i=0; $i<count($file); $i++) 
{
	list ($field1, $field2, $field3, $field4) = split ('\|', $i);
	if ($field1!=$id) 
	{ 
		$data .= $field1.'|'.$field2.'|'.$field3.'|'.$field4."\n"; 
	}
} 
fclose($file);
$fp = fopen('clients.txt','w');
fwrite($fp,$data);
fclose($fp); 
?>

and my friend suggested putting it all in a table, and deleting the line, and overwriting the file.
no idea of how to do this....

Oh, my database is kinda like this.

23453|maxicube|admin|305
23454|fish|user|28

Also, if i run that.
this is all that returns on clients.txt

0|||

thanks for your help - Maxicube :D

Edited by maxicube: n/a

4
Contributors
7
Replies
10
Views
7 Years
Discussion Span
Last Post by almostbob
0

what about writing the entire thing in some other file except that particular line & then deleting the first file,making the second file as main FFD.
Or even think about having the unique field value for the records, as a line numbers, so that it will be easy to delete

0

GAH!
tried doing that, to no avail.

new code:

<?php

$file = fopen('clients.txt',r);
$ip = $_SERVER['REMOTE_ADDR'];

$fp = fopen('client.txt','a')
for ($i=0; $i<count($file); $i++) 
{
	list ($field1, $field2, $field3, $field4) = split ('\|', $i);
	if ($field1!=$ip) 
	{ 
		fwrite($fp,$i."\n"); 
	}
} 
fclose($fp); 
?>7

new error

Parse error: syntax error, unexpected T_FOR in *snip*/test.php on line 7

Edited by maxicube: n/a

0

*sigh* silly me - just woke up
ok, now thats out of the way.
all that returns in the client.txt (not clients.txt)
is the number 0.

0
<?php $file = fopen('clients.txt',r);
$fp = fopen('client.txt','a');
$ip = $_SERVER['REMOTE_ADDR']; 
for ($i=0; $i<count($file); $i++) {
$list=fgetcsv( $file,1000,'|');	
if ($list[0]!=$ip) { fputcsv($fp,$list,'|'); } }
fclose($fp);
fclose($file);  ?>

have not verified syntax this is a thought exercise

Edited by almostbob: n/a

0

after cleaning your code.

<?php
$file = fopen('clients.txt','r');
$ip = $_SERVER['REMORE_ADDR'];
$fp = fopen('client.txt','a');

for ($i=0; $i<count($file); $i++)
{
	$out = fgetcsv($file,1000,'|');
	if ($out[0]!=$ip)
	{
		fwrite($fp,$out);
	}
fclose($fp);
fclose($file);
}
?>

it spits out "ArrayArray" into client.txt

0

have not verified syntax this is a thought exercise

You can find how to solve the syntax problem in the php manual
I pulled that code out of my **expletive deleted**

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.