Use the file() function to open the file. It opens the file and put each line in an array...
Example :
$fichier = file("./datas.txt");
first line = $fichier[0]
second line = $fichier[1]
line x = $fichier[x - 1]
Then, use array_search() :
Description
mixed array_search ( mixed needle, array haystack, boolean strict)
(see php.net)
That function will return the line if needle is found in the array haystack, or false if it doesn't find it.
Example :
$line = array_search("lina", $fichier, FALSE);
Now, you (may) have the line number. So you can edit it...
if($line) {
$fichier[$line] = "lina doesn't exist anymore... now it's Rachelle !";
}
To delete a line, use array_splice() :
array array_splice ( array input, int offset [, int length [, array replacement]])
(again, see PHP.net)
array_splice($fichier, $line, 1);
Now, to write the file back...
$contenu = implode("\n", $fichier);
$fp = fopen("./datas.txt", "w+");
fputs($fp, $contenu);
fclose($fp);
I didn't test the code, so if there are bugs, tell me !