SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help "extracting" text from a file...

    I'm trying to extract a certain range of text from a file, edit it, and then put it back. I hope someone can help me.

    Let's say I have a file like this:[quote]
    asdjfasdlfads
    fasd
    fasd
    ffasdf <!-- #startoftext comment here-->This part here is what I want to get
    and here
    and more
    and also here<!-- #endoftext -->asldjfalsdjfalskdjfasd
    fasd
    asd
    fasd
    f[/quote
    So everything between the two html comments is what I need to "extract".

    Does anyone know how to do this? Any code samples I can use to learn how to do it?

    My end goal is to extrac the text between the comments, put it into a textbox, edit it, and then save it back to the file after editing.

    Thanks!
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try rigging it like this, just create unique "start" and "end" markers for each segment you'd want to extract...
    PHP Code:
    <?
    // Load full text into variable
    $text "
    whatever whatever whatever
    <!--#start_marker-->
    This part here is what I want to get
    and here
    and more
    and also here
    <!--#end_marker-->
    whatever whatever whatever
    "
    ;

    // strip out unwanted text
    $text split('<!--#start_marker-->',$text);
    $text split('<!--#end_marker-->',$text[1]);
    $text $text[0];

    // echo just the part you want
    echo $text;
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •