Hi Nick!
First off, *please* read a netiquette guide before posting -- I hate
seeing a conational of mine posting a message like yours ("###PLEASE
HELP###" and "I am waiting for an answer" are extremely rude - you're
not paying for support on this mailing list, so you can't demand
anything). Other than that, I'd point out cleaning up your code before
posting because we don't have to read through your "slickiness" -- but
that may be a matter of personal opinion.
Your problem resides exactly in your code's slickiness - which
incidentally doesn't make it any faster. Try this conventional code instead:
function delete_user($sterge_user, $path) {
[1]
$fisierul=$orig=file($path);
for($i=0;$i<sizeOf($fisierul);$i++) {
list($uname,,,,)=explode(":",$fisierul[$i]);
if ($uname==$sterge_user) {
$fisierul=array_splice($fisierul,$i,1);
$i--;
}
}
if ($fisierul!=$orig) {
[...]
}
[2]
}
[...] contains the trivial task of imploding $fisierul (using "\r\n" or
"\n", depending on the OS) and writing it. Make sure you check for and
create a lock file at [1] and respectively unlink it at [2] -- or simply
use a database instead, for that matter.
Anyway, just in case you *really* want to use your original code, the
problem is that the code (probably) finds the line to delete but doesn't
go any further than that - plus it's consuming unnecessary resources by
rewriting the file line by line.
Bogdan
Radio X wrote:
> i have a text file with some of this elements:
>
> name:adress:telephone:email:password
>
> i want to delete this line using for identifier the 'name' only.
>
> // $sterge_user="name"; this is the value sent by form witch will be the identifier
> // $path="some_of_my_files"; the file used here allready set with 777 chmod
>
> function delete_user($sterge_user, $path){
> $i = 0;
> $fisierul = file($path);
> $fp = fopen($path, "w");
> while (!sizeof($fisierul))
> {
> $data = fgetcsv ($fisierul, 4096, ":");
> if ($data[0]==$sterge_user)
> {
> for ($i=0; $i<=sizeof($data);){$data[i]="";++$i;}
> }
> fwrite($fp, $data);
> }
> fclose($fp);
> }
>
> I am waiting for an answer, please
>
> Nick
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php