SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot amit290's Avatar
    Join Date
    Oct 2001
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    read / output a CSV file

    I've got a CSV file I need to output. The content format is like this:

    adcr1;6
    adcr2;11
    adcr3;1
    adopen;36
    brama9;1
    bsb2b;5
    bsb2c;1
    memg9;5

    Is it possible to split the content where the semi-colon is so I can output it like this:

    ADCR1 = 6
    ADCR2 = 11
    ADCR3 = 1
    etc.

    Also how do I get them to appear on seperate lines? They are on seperate lines in the CSV file.

    Thnx

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amit290

    Also how do I get them to appear on seperate lines? They are on seperate lines in the CSV file.
    Do you have to use php?

    it shouldn't be hard.. I don't know the syntax, but basically break each componet up into a variable (or you can use an array) then just output them from the variables and concatnate them with an equals sign. The hardest part will proably be opening and reading the file.
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  3. #3
    SitePoint Addict BenANFA's Avatar
    Join Date
    Apr 2003
    Location
    Bath, UK
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Opening and reading a file isn't hard try

    PHP Code:
    $file_line file( <FileName> ); 
    This assigns $file_line as an array with each array entry being a string contining 1 line of the file

    then you can do something like

    PHP Code:
    foreach( $file_line as $line )
    {
      
    $line trim($line);

      
    /* Skip blank lines */
      
    if ( == strlen$line ) )
        continue;

      
    $line_data explode ";"$line );

      echo( 
    $line_data[0] . " = " $line_data[1] . "\n" );


  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or str_replace(';', '=', $line).
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure


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
  •