HOT DO EXPLODE() THIS INTO DATABASE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • voipcanada

    HOT DO EXPLODE() THIS INTO DATABASE

    Here is the sample text (( http://starkom.com/bill20050820_000000 ))

    wanted to know if there is some other function like explode to split
    the = sign in each array

  • Joachim Weiß

    #2
    Re: HOT DO EXPLODE() THIS INTO DATABASE

    voipcanada schrieb:[color=blue]
    > Here is the sample text (( http://starkom.com/bill20050820_000000 ))
    >
    > wanted to know if there is some other function like explode to split
    > the = sign in each array
    >[/color]
    perhaps split is the function you are looking for.

    However if you don't want to use php: man awk.

    HIH

    Jo

    Comment

    • voipcanada

      #3
      Re: HOT DO EXPLODE() THIS INTO DATABASE

      ok thanks ,,,,,,

      Comment

      • Mladen Gogala

        #4
        Re: HOT DO EXPLODE() THIS INTO DATABASE

        On Sun, 28 Aug 2005 14:01:19 -0700, voipcanada wrote:
        [color=blue]
        > Here is the sample text (( http://starkom.com/bill20050820_000000 ))
        >
        > wanted to know if there is some other function like explode to split
        > the = sign in each array[/color]

        This is not going to work with the simple split. You'll first have to
        split using ",\s+" and then, in turn, to split each array element of the
        resulting array using "=" as delimiter. The code would look like this:

        #!/usr/local/bin/php
        <?php
        $fh = fopen("/tmp/myfile.txt", "r");
        while (!feof($fh)) {
        $buff = fgets($fh, 4096);
        $line = preg_split("/,\s+/", "DATE=$buff ");
        foreach($line as $elem) {
        $pair = preg_split("/=/", $elem);
        @$parsed[$pair[0]] = $pair[1];
        }
        print_r($parsed );
        $parsed = array();
        }
        fclose($fh);
        ?>

        The output look like this:

        Array
        (
        [DATE] => Sat Aug 20 18:20:20 2005
        [HOST] => 66.24.17.72
        [SRC-NUMBER-IN] => 8565686628
        [DST-NUMBER-IN] => 888#8565487318
        [SRC-NUMBER-OUT] => 8565686628
        [DST-NUMBER-OUT] => 888#8565487318
        [SRC-NUMBER-BILL] => 8565686628
        [DST-NUMBER-BILL] => 888#8565487318
        [SRC-IP] => 66.24.17.71:112 98
        [DST-IP] => 216.223.144.110 :1720
        [SRC-USER] => ANDY001IN
        [DST-USER] => ANDY002OUT
        [SRC-NAME] => ANDY001IN
        [DST-NAME] => ANDY002OUT
        [DIALPEER-NAME] => R36
        [INITIAL-INCOMING-LOCAL-ADDRESS] => 66.24.17.72
        [SELECTED-INCOMING-LOCAL-ADDRESS] => 66.24.17.72
        [OUTGOING-LOCAL-ADDRESS] => 66.24.17.72
        [RECORD-ID] => 1124534625-61
        [ELAPSED-TIME] => 42
        [SETUP-TIME] => 18:19:38.000 GMT Sat Aug 20 2005
        [CONNECT-TIME] => 18:19:38.000 GMT Sat Aug 20 2005
        [DISCONNECT-TIME] => 18:20:20.000 GMT Sat Aug 20 2005
        [DISCONNECT-CODE-LOCAL] => 1
        [DISCONNECT-CODE-Q931] => 16
        [SRC-BYTES-IN] => 126957
        [DST-BYTES-IN] => 18276
        [SRC-BYTES-OUT] => 18308
        [DST-BYTES-OUT] => 126494
        [QOS] => 11
        [SRC-CODEC] => g729
        [DST-CODEC] => g729
        [CALLID] => 083b3cbf10fb11d a8ba0837c360ba9 85
        [CONFID] => 083b3cbf10fb11d a8b9e837c360ba9 85
        [PROXY-MODE] => 1
        [ROUTE-RETRIES] => 1

        )

        That is, I believe, what you want to achieve.



        --


        Comment

        • Mladen Gogala

          #5
          Re: HOT DO EXPLODE() THIS INTO DATABASE

          On Sun, 28 Aug 2005 23:06:58 +0200, Joachim Weiß wrote:
          [color=blue]
          > However if you don't want to use php: man awk.[/color]

          No need for lame tools like awk. PHP can do it perfectly well.

          --


          Comment

          • voipcanada

            #6
            Re: HOT DO EXPLODE() THIS INTO DATABASE

            thank you works really well ,, kind regards

            Comment

            • voipcanada

              #7
              Re: HOT DO EXPLODE() THIS INTO DATABASE

              hi

              many i ask you one more question ,,, $buff = fgets($fh, 4096); what
              does 4069 mean ,,
              Is it for number of lines to import ,, thanks for your responce

              Comment

              • Tim Van Wassenhove

                #8
                Re: HOT DO EXPLODE() THIS INTO DATABASE

                On 2005-09-13, voipcanada <voipcanada@gma il.com> wrote:[color=blue]
                > hi
                >
                > many i ask you one more question ,,, $buff = fgets($fh, 4096); what
                > does 4069 mean ,,[/color]

                rtfm http://www.php.net/fgets

                --
                Met vriendelijke groeten,
                Tim Van Wassenhove <http://timvw.madoka.be >

                Comment

                Working...