find and delete specific line from text file
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
deleteitem.php
if(isset($_GET['pname']))
            {
                $pname = trim($_GET['pname']);  

            }
Info

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

<?php
        if(isset($_GET['pname']))
        {
            $pname = trim($_GET['pname']);  

            $string = file_get_contents('../data/cart.txt');
            $exploded = explode("\n", $string);

            foreach ($exploded as $key => $val)
            {
                if (stristr($val,$pname))
                {
                    $returned[$key] = $val;
                }


                $string_with_removed = implode("\n", $returned);
                file_put_contents('../data/cart.txt', $string_with_removed);
            }


            header('refresh:2;url=../cart.php');
        }

        echo "<p>Deleting Item</p>";
?>

that the code i have but its not working

if you say its not working, what does it mean.
yOu get error, or you get some different output or what happening, tell exactly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.