Hey guys, I've searched around and nothing is 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 details
is a string.
I have a client page (locked under user-pass) i开发者_StackOverflown 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,
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.
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
精彩评论