Parse nightmare

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

    Parse nightmare

    I have a 1200 line text file with information that I need in the following
    format.
    FIGURE>SAMEFIGU RE=NUMBER>SAMEN UMBER=CHANNELNA ME">SAMECHANNEL NAME<DELETE

    I want to break it down into this format.
    $figure > $figure = $number > $number = $channel ">
    $channel < the rest can be deleted
    my way (not a lot of experience with this sort of problem..
    don't laugh)

    explode (">", $exFigure);
    $figure = $exFigure[0];

    explode ("=", $number);
    $figure = $exFigure[1];
    // then chop out after the >
    And so on..


    Would there be a better way I could learn...?

    Thanks alot in advance

    Mike.


  • Dmitry Ruban

    #2
    Re: Parse nightmare

    Hello Mike,

    Try to use regular expressions.
    For exmaple:
    pref_match ( "/([^>]+)>([^=]+)=(\d+)>(\d+)= ([^\"]+)\"/", $exFigure,
    $matches );
    $matches[1] = FIGURE
    $matches[2] = SAMEFIGURE
    $matches[3] = NUMBER
    $matches[4] = SAMENUMBER
    $matches[5] = CHANNELNAME

    Excuse my bad pattern, im hurry :)

    Dima
    [color=blue]
    > I have a 1200 line text file with information that I need in the following
    > format.
    > FIGURE>SAMEFIGU RE=NUMBER>SAMEN UMBER=CHANNELNA ME">SAMECHANNEL NAME<DELETE
    >
    > I want to break it down into this format.
    > $figure > $figure = $number > $number = $channel ">
    > $channel < the rest can be deleted
    > my way (not a lot of experience with this sort of problem..
    > don't laugh)
    >
    > explode (">", $exFigure);
    > $figure = $exFigure[0];
    >
    > explode ("=", $number);
    > $figure = $exFigure[1];
    > // then chop out after the >
    > And so on..
    >
    >
    > Would there be a better way I could learn...?
    >
    > Thanks alot in advance
    >
    > Mike.
    >
    >[/color]


    Comment

    • Andy Hassall

      #3
      Re: Parse nightmare

      On Wed, 8 Oct 2003 16:45:59 -0700, "Michael Willcocks"
      <michael@metrog roup.com.au> wrote:
      [color=blue]
      >I have a 1200 line text file with information that I need in the following
      >format.
      >FIGURE>SAMEFIG URE=NUMBER>SAME NUMBER=CHANNELN AME">SAMECHANNE LNAME<DELETE
      >
      >I want to break it down into this format.
      >$figure > $figure = $number > $number = $channel ">
      >$channel < the rest can be deleted
      >my way (not a lot of experience with this sort of problem..
      > don't laugh)
      >
      >explode (">", $exFigure);
      >$figure = $exFigure[0];
      >
      >explode ("=", $number);
      >$figure = $exFigure[1];
      >// then chop out after the >
      >And so on..
      >
      >Would there be a better way I could learn...?[/color]

      Using explode here sounds quite reasonable; so long as the delimiter is never
      part of the data, there's no real need to use anything more complicated.

      --
      Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

      Comment

      • Michael Willcocks

        #4
        Re: Parse nightmare

        Thank you both for your input
        Thanks alot seems to be working.
        I have never used the pattern method because any time I have seen it in
        use... It looks a little scary.

        "Andy Hassall" <andy@andyh.co. uk> wrote in message
        news:2so8ovck75 fuvd9a6v99e79b7 1ofsgh8ln@4ax.c om...[color=blue]
        > On Wed, 8 Oct 2003 16:45:59 -0700, "Michael Willcocks"
        > <michael@metrog roup.com.au> wrote:
        >[color=green]
        > >I have a 1200 line text file with information that I need in the[/color][/color]
        following[color=blue][color=green]
        > >format.
        > >FIGURE>SAMEFIG URE=NUMBER>SAME NUMBER=CHANNELN AME">SAMECHANNE LNAME<DELETE
        > >
        > >I want to break it down into this format.
        > >$figure > $figure = $number > $number = $channel ">
        > >$channel < the rest can be deleted
        > >my way (not a lot of experience with this sort of problem..
        > > don't laugh)
        > >
        > >explode (">", $exFigure);
        > >$figure = $exFigure[0];
        > >
        > >explode ("=", $number);
        > >$figure = $exFigure[1];
        > >// then chop out after the >
        > >And so on..
        > >
        > >Would there be a better way I could learn...?[/color]
        >
        > Using explode here sounds quite reasonable; so long as the delimiter is[/color]
        never[color=blue]
        > part of the data, there's no real need to use anything more complicated.
        >
        > --
        > Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
        > Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]


        Comment

        Working...