Results 1 to 5 of 5

Thread: Deleting From A File

  1. #1
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428

    Deleting From A File

    Edit: Got it sorted for the most part. I was way off, heh.

    I've been working on this for a while, and I've gotten close, just not close enough. So far it'll delete one line but not multiple lines. Basically I have a listbox:

    Code:
    <select name='merchants[]' multiple="multiple">
    <option value="8334">8334 - Playful Plush Toys</option>
    <option value="4742">4742 - Nature Hills Nursery</option>
    </select>
    In a txt file I have:

    8334,Playful Plush Toys
    4742,Nature Hills Nursery
    And I'm trying to open that file and delete any lines that match what's been selected in the listbox. Here's my, probably horribly, code.

    PHP Code:
    // horrible code removed 
    Again, it works with one line, but not multiple. Selecting multiple lines only removes the first line, and rewrites the file with an initial comma delimited blank line, followed by the second entry.
    Last edited by mobilebadboy; 12-15-2008 at 06:03 AM.
    Shawn Kerr .com

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Whatcha building with linkshare's merchandiser system?

    And why not use a database? Databases are built for exactly this kind of operation you know.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    Yeah, DBs are always easier, but for the little bit of info I'm storing it's not worth it. Plus I want it as portable, with little if any footprint, as possible. It's actually for ShareASale, it's a script that automatically downloads my merchants' feeds from SAS' FTP and imports them to the database.

    I originally wrote it where you had to fill in all the info (DB info, SAS FTP info, merchant ID, etc) for each merchant. Now I can add/delete merchants (from the txt file) and all the rest of the stuff is stored in a config file. Now it's simply selecting the merchant from a dropdown and hitting Go.
    Shawn Kerr .com

  4. #4
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    When I did a similar thing I did it all with cron. I really don't know how to do text file editing to the degree you want with PHP. open, read, append, write, thats all I've ever done.

    Maybe open the file into an array. Then rewrite the file in php with a simple conditional statement that doesn't let the one you want deleted to be part of the rewrite.

    So technically your script is doing more heavy lifting, copying the entire file, then writing over it with one small change, but the programming is fairly straightforward.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  5. #5
    Roll Tide! mobilebadboy's Avatar
    Join Date
    Apr 2004
    Location
    Mobile, AL
    Posts
    428
    Yeah, I do have many of my larger feeds setup on cron. This script is part for myself, part for others, those who are 'clueless' when it comes to feeds. Another reason I'm using a text file for the merchant IDs, to keep it simple. One day I got tired of post after post at ABestWeb -- 'how do I download a feed,' 'how do I get it in my database', etc.

    It'll connect to SAS' FTP, download the feed to the server, connect to the database and create a temp table, import the feed into that table, then rename it to whatever main table name is used for actually calling the queries from (to minimize downtime for the main table).

    After that they're on their own.

    Its downloadable from shawnkerr.com/sasftp/. But since I just rewrote the entire thing, I haven't had time to clean it up since I have other things to do, so the code looks nasty.
    Shawn Kerr .com

Similar Threads

  1. How do I write and retrieve strings from a text file using PHP?
    By KLB in forum Website Programming & Databases
    Replies: 7
    Last Post: 06-04-2008, 10:27 PM
  2. A Resource Directory of File Extensions
    By ! search-engines- in forum General Chat
    Replies: 0
    Last Post: 01-20-2006, 11:31 PM
  3. File Name VS Directory Name
    By Yasodaran in forum Search Engine Optimization
    Replies: 7
    Last Post: 02-14-2004, 04:43 PM

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
  •