extracting delimited text from a file

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

    extracting delimited text from a file

    I want to extract several lines from an html file that begin with pattern1
    and end with pattern2 and ignore everything before pattern1 and after
    pattern2. Any snippets or suggestions will be greatly appreciated.

    Best,
    Christopher


  • Pedro Graca

    #2
    Re: extracting delimited text from a file

    Christopher Glaeser wrote:[color=blue]
    > I want to extract several lines from an html file that begin with pattern1
    > and end with pattern2 and ignore everything before pattern1 and after
    > pattern2. Any snippets or suggestions will be greatly appreciated.[/color]

    preg_match_all( ) is your friend


    example:
    <?php
    $data = 'p1p2p3p4p5p6p5 p4p3p2p1p2p3p4p 5p6';
    $pat1 = 'p2';
    $pat2 = 'p5';

    preg_match_all( "@$pat1(.*)$pat 2@Uim", $data, $matches);
    echo '<pre>'; print_r($matche s); echo '</pre>';
    ?>

    NOTE: script typed directly and NOT tested.

    PS: I found another use for double quotes :)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    Working...