Results 1 to 2 of 2
  1. #1
    Full Member
    Join Date
    January 17th, 2005
    correct line 1 of CSV in place
    I have a series of CSV files that have a spurious comma at the end of line 1 of the file e.g.


    There are too many and theyare too big to make downloading, correcting on my PC and uploading again a sensible option as whilst my broadband is now up to over 2Mb download, the upload is trailing behind at 300k

    I thought I would write some PHP to generate a list of .csv files in the folder and then for each file, open it, read line 1 and then rewrite it without the trailing comma.

    However I can't seem to find a function in PHP that will do an update in place to write line 1 back.

    Does anyone know whether it is possible in PHP to do an update in place.

    I suspect if it is not possible in PHP then maybe it is possible in Perl but I have never really got to grips with Perl.

    The fallback is not to do the rewrite in place but to write each file out to a brand new copy with a corrected line 1 , but does seem like an inefficient way of going about things, but that might just be my old fashioned mainframe mindset.


  2. #2
    Full Member
    Join Date
    January 17th, 2005
    Problem Solved !!
    Having slept on it I remembered that I had written a php script some time ago to read a csv file and generate SQL INSERT statements when I was having problems with my ISP and SQL LOAD FILE

    So I updated that with some extra processing after the fgetcsv for line 1 so that if the last name in the array from the fgetcsv was null I did a array_pop to remove it.

    As a bonus this code, that I forgot about, does not just do an insert for each line in the CSV file but saves each data line read and then builds a big insert with all the values accumulated, so that it runs pretty fast.

    I orginally wrote this as one of my ISP had quite a low size limit on SQL LOAD FILE statement but now glad that circumstances have made me review it.

    Now I have got a different problem as the datafeed column names have changed. Still that is a dead simple coding job of having a lookup table with replacement values

  3. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Help with .csv
    By rematt in forum PopShops
    Replies: 11
    Last Post: May 15th, 2007, 02:42 PM
  2. Help, Csv????
    By phc1127 in forum ShareASale - SAS
    Replies: 3
    Last Post: October 26th, 2006, 11:24 PM
  3. CSV 2 HTML
    By affiliateking in forum Programming / Datafeeds / Tools
    Replies: 12
    Last Post: July 20th, 2002, 02:00 PM

Posting Permissions

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