cart.txt (tab delimated)
guiburi PID001 KARLSTAD Sofa 2348 2 4696
guiburi PID002 BESTA Cabinet 1656 32 52992
guiburi PID009 PAX Wordrobe 1794 2 3588
$pname = trim($_GET[‘pname’]);
pname is sent from a another file using url and it used to match with the 3rd colum of the cart file and then delete the line.write back to the same file
ive tried many ways but no luck. any help? thanks
Are you using fgetcsv? If so it would be a simple matter of looping though the resulting array.
The general principal would be as follows
- Read the file with [fphp]file_get_contents[/fphp]
- Get the separate lines in an array using [fphp]explode[/fphp] by "
", let’s call this $lines
- For each of those lines
3a) [fphp]explode[/fphp] the line on "\ "
3b) Check if the third element of the result of 3a equals $pname
3c) If it does, remove the element from $lines
- [fphp]implode[/fphp] the array $lines with "
- Write the data back to the file using [fphp]file_put_contents[/fphp]