How to remove a chapter from a string?!

Discussion in 'PHP' started by redhits, Oct 22, 2009.

  1. #1
    I have lot's of files , and i would like to remove some chapters from them.

    The "chapeters" i want to remove can not be removed via str_replace, because they are not a string, they are something like

    text text
    BIOGRAPHY
    book1 , bla bla bla bl
    book2 , bla bla bla bl
    book3 , bla bla bla bl
    book4 , bla bla bla bl
    </div></html>
    text text text

    So i would like to remove everything starting from BIOGRAPHY to </div></html>


    ....
     
    redhits, Oct 22, 2009 IP
  2. kind_of_the_cash

    kind_of_the_cash Active Member

    Messages:
    852
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    85
    #2
    kind_of_the_cash, Oct 22, 2009 IP
  3. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #3
    Well i want the opposite of that thing :) remove everything from biography and keep the rest :)
     
    redhits, Oct 22, 2009 IP
  4. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #4
    You may try something like
    
    $text = preg_replace('{BIOGRAPHY.*?</div></html>}msi','',$text);
    
    PHP:
     
    Gray Fox, Oct 22, 2009 IP
  5. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #5
    heh ,does anybody know an understandable website about this preg_replace? for every dumbass like me?!
     
    redhits, Oct 22, 2009 IP
  6. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    preg_replace isn't the end of the line when it comes to php scripting, as i used to think it was.

    http://www.regular-expressions.info/reference.html

    and it isn't quite as difficult as it looks, you just need to start practising. it's usually helpful if you can say in English what the regex actually implies, try using "The Regex Coach" (it's a windows software) - it explains regular expressions in English as you type them.
     
    szalinski, Oct 22, 2009 IP