getting text between two comments

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

    getting text between two comments

    I have access to a page that stores data as HTML. The code has two comments
    around the data that I want to get called <!-- START --> and <!-- END -->

    Question is, how do i read the page and grab the code that is between these
    two comments

    Nigel


  • Tim Van Wassenhove

    #2
    Re: getting text between two comments

    On 2004-01-12, Nigel <nobody@here.co m> wrote:[color=blue]
    > I have access to a page that stores data as HTML. The code has two comments
    > around the data that I want to get called <!-- START --> and <!-- END -->
    >
    > Question is, how do i read the page and grab the code that is between these
    > two comments[/color]

    You can find all your answers in the manual. http://www.php.net/manual

    Opening, reading and closing a file -> file functions.
    Finding something in a string -> string functions.


    --

    Comment

    • Chung Leong

      #3
      Re: getting text between two comments

      To read the page, use file_get_conten ts(<filename>). To get the code use
      preg_match(), like this:

      if(preg_match('/<!-- START -->(.*)<!-- END -->/', $html, $matches)) {
      $code = $matches[1];
      }

      Uzytkownik "Nigel" <nobody@here.co m> napisal w wiadomosci
      news:btueap$pra $1$8300dec7@new s.demon.co.uk.. .[color=blue]
      > I have access to a page that stores data as HTML. The code has two[/color]
      comments[color=blue]
      > around the data that I want to get called <!-- START --> and <!-- END -->
      >
      > Question is, how do i read the page and grab the code that is between[/color]
      these[color=blue]
      > two comments
      >
      > Nigel
      >
      >[/color]


      Comment

      • Chung Leong

        #4
        Re: getting text between two comments

        Oops, forgot the s modifier. Should be like this:

        if(preg_match('/<!-- START -->(.*)<!-- END -->/s', $html, $matches)) {
        $code = $matches[1];
        }

        Uzytkownik "Chung Leong" <chernyshevsky@ hotmail.com> napisal w wiadomosci
        news:BqudnfxkS5 N4op7dRVn-sw@comcast.com. ..[color=blue]
        > To read the page, use file_get_conten ts(<filename>). To get the code use
        > preg_match(), like this:
        >
        > if(preg_match('/<!-- START -->(.*)<!-- END -->/', $html, $matches)) {
        > $code = $matches[1];
        > }
        >
        > Uzytkownik "Nigel" <nobody@here.co m> napisal w wiadomosci
        > news:btueap$pra $1$8300dec7@new s.demon.co.uk.. .[color=green]
        > > I have access to a page that stores data as HTML. The code has two[/color]
        > comments[color=green]
        > > around the data that I want to get called <!-- START --> and <!--[/color][/color]
        END -->[color=blue][color=green]
        > >
        > > Question is, how do i read the page and grab the code that is between[/color]
        > these[color=green]
        > > two comments
        > >
        > > Nigel
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...