how can i extract text between <body> and </body> using preg_match ?

Discussion in 'PHP' started by ramysarwat, Nov 4, 2009.

  1. #1
    how can i extract text between <body> and </body> using preg_match ?

    note:
    <body> maybe have another strings and spaces inside
    </body> maybe have another strings and spaces inside
     
    Last edited: Nov 4, 2009
    ramysarwat, Nov 4, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    /<body>(.*)<\/body>/iUms
    Code (markup):
     
    javaongsan, Nov 4, 2009 IP
  3. ramysarwat

    ramysarwat Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you javaongsan but what is iUms

    if you can explain it all that will be great
     
    ramysarwat, Nov 4, 2009 IP
  4. emilybarbie

    emilybarbie Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ex:

    preg_match('/<body>(.*)<\/body>/s',$html,$content_arr);

    $text=$content_ar[1];
     
    emilybarbie, Nov 5, 2009 IP
  5. ramysarwat

    ramysarwat Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thank you emilybarbie but not working too. any ideas why ?
     
    ramysarwat, Nov 5, 2009 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    nico_swd, Nov 5, 2009 IP
  7. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #7
    They are Pattern Modifiers
    i-match both upper and lower case letters.
    m-content can be multiline
    s-matches all characters, including newlines.
    U-inverts the "greediness" of the quantifiers so that they are not greedy by default
     
    javaongsan, Nov 5, 2009 IP