+ Reply to Thread
Results 1 to 3 of 3

 

Thread: convert from csv to tab delimited using PHP

  1. #1
    learning slowly

    Status
    Offline
    Join Date
    Jan 2006
    Location
    Norfolk
    Posts
    157
    Thanks
    5
    Thanked 5 Times in 5 Posts


    Hi all

    Heres my problem

    I have a product file in csv that I would like to parse and place in a MYSQL table. I am running into problems with the product descriptions containing commas because the comma is used as the delimiter. If I convert the csv to tab manually, my code is fine and everything parses correctly.

    My Question

    Is it possible to use PHP to convert a file from csv to tab delimited so I don't have to manually convert it, or does somebody know of any easy way of escaping the commas in the descriptions and leaving the file as a csv?

    My head is now hurting.

    Thanks

    Andy
    Gift Ideas Wizard | In to coarse fishing? Read my Coarse Fishing Blog

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Jul 2005
    Location
    North Devon
    Posts
    899
    Thanks
    13
    Thanked 21 Times in 21 Posts
    use fgetcsv loop through each line inserting as you go?

    somthing like
    PHP Code:
    $myfile "path/to/csv.csv";
    // open for reading
      
    $csv_fp fopen ($myfile"r");

       
    // add a counter for fun may come in ron!
     
    $rows 0;
    // start loop
              
    while ($data fGetCsv ($csv_fp10000",")) 
    {
    // un delimit if your first row of the csv is a column header
    // if($rows == 0){
    // do nothing as its column header
    // }else{ // do insert

    // how many columns? 
    $num count($data);

    for (
    $c=0$c $num$c++) {
           echo 
    $data[$c] . "<br />\n";
       }

    // }

    // Count 
    $rows++;

    // End the loop


              
    fclose ($csv_fp); 
    Last edited by futureweb; 09-05-06 at 05:25 PM.

  3. #3
    learning slowly

    Status
    Offline
    Join Date
    Jan 2006
    Location
    Norfolk
    Posts
    157
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Thanks for the reply, will read through it and see if I can make sense of it.

    Cheers

    Andy
    Gift Ideas Wizard | In to coarse fishing? Read my Coarse Fishing Blog

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. xml > csv into mysql with a sprinkle of php
    By morleymouse in forum Programming
    Replies: 4
    Last Post: 08-12-04, 03:13 PM
  2. Anyone anygood with xml, php, mysql and Affiliate Window
    By AnnonnyMouse in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 23-09-04, 12:00 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
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2