read from file with delimiters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boris ©avc

    read from file with delimiters

    How do I read data from file with delimiters (for instance A;B;ccc;S45A;UU )?
    I'd like to write that data to MYSQL table...

    Thanks for the help,
    Boris Savc


  • Jon Kraft

    #2
    Re: read from file with delimiters

    "Boris ©avc" <boris.savc@odi s-info.com> wrote:
    [color=blue]
    > How do I read data from file with delimiters (for instance
    > A;B;ccc;S45A;UU )? I'd like to write that data to MYSQL table...[/color]

    Please don't multipost!

    PHP:
    Have a look into fgetcsv():
    Gets line from file pointer and parse for CSV fields


    MySQL:
    Have a look into LOAD DATA INFILE:


    HTH;
    JOn

    Comment

    • John Dunlop

      #3
      Re: read from file with delimiters

      Boris ©avc wrote:
      [color=blue]
      > How do I read data from file with delimiters (for instance A;B;ccc;S45A;UU )?[/color]

      Gets line from file pointer and parse for CSV fields


      --
      Jock

      Comment

      • Fred H

        #4
        Re: read from file with delimiters

        På Tue, 24 Feb 2004 11:27:58 +0100, skrev Boris ©avc
        <boris.savc@odi s-info.com>:
        [color=blue]
        > How do I read data from file with delimiters (for instance
        > A;B;ccc;S45A;UU )?
        > I'd like to write that data to MYSQL table...[/color]

        This is -one- way of doing it:

        $lines = array(); //Create an array.
        $lines = file("my_delime d_data_file.dat ");//Load the lines into the array.
        foreach($lines as $line) { //Loop through the array.
        list($field1,$f ield2,$field3,$ field4,$field5) = explode(";",$li ne);
        //Extract your vars from the line.
        mysql_query("IN SERT INTO your_table ('field1',___,' field5')
        VALUES(".$field 1.",___,".$fiel d5.")"); //Insert them into the db.
        }//End of loop

        The ___ part is of course just "fill in the blanks yourself".
        The code is of course not complete, but you get the general idea.


        --
        Fred H

        void FredH::Contact( ) {
        TextToSpeach.sa y("frode at age dee dee dot en oh");
        }

        Comment

        Working...