SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Manipulating Flat Text Files Tab Delimated

    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

  2. #2
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Are you using fgetcsv? If so it would be a simple matter of looping though the resulting array.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The general principal would be as follows

    1) Read the file with file_get_contents
    2) Get the separate lines in an array using explode by "\n", let's call this $lines
    3) For each of those lines
    3a) explode the line on "\t"
    3b) Check if the third element of the result of 3a equals $pname
    3c) If it does, remove the element from $lines
    4) implode the array $lines with "\n"
    5) Write the data back to the file using file_put_contents

    Off Topic:

    IKEA?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •