views:

31

answers:

2

Hey guys, ive search around and nothing ius QUITE what i need, i am horrible with php thus far.

Basically, i have a text file serving as a database.

each line has the form:

id|lat|lng|details

where:

id is a unique integer, lat and lng are float and string details.

I have a client page (locked under user-pass) in which the user enters the unique id and a PHP script should delete the line in the file which has that unique id.

How do i accomplish this?

Thanks,

+6  A: 

This is a very, very bad idea. Any simple way to solve this will be horribly racy. Any complete way will leave you wanting to use a real database.

If you insist on continuing, the way to do this is to copy every other line to a new file, then rename the new file back into place.

Ignacio Vazquez-Abrams
+1. To clarify slightly, by "racy", Ignacio almost certainly means "prone to race conditions": http://en.wikipedia.org/wiki/Race_condition#File_systems
Frank Farmer
A: 

say the user id is "1" from user input

$input="1";
$data = file("file");
$matches = preg_grep("/^".$input."\|/",$data,PREG_GREP_INVERT);
print_r($matches);

$matches contains the lines you want. Use file_put_contents or fopen()/fwrite() etc to output to file

ghostdog74