Preg Match Question

Discussion in 'PHP' started by SNaRe, Jan 25, 2008.

  1. #1
    I have a data in my string. This post_message_2052965 is different everytime
        <div id="post_message_2052965">Hello Everyone<br />
    <br />
    There is a good movie for you all, a good creation from Mrinal Sen. <br />
    Cast:Utpal Dutt, Suhasini Muley, Shekar Chatterjee and others...<br />
    Story by Banafool<br />
    VCD quality, Size: 930MB<br />
    <br />
    Hope you will like and if so please leave your comments...</div>
    HTML:
    I want this to filter like

    Hello Everyone<br />
    <br />
    There is a good movie for you all, a good creation from Mrinal Sen. <br />
    Cast:Utpal Dutt, Suhasini Muley, Shekar Chatterjee and others...<br />
    Story by Banafool<br />
    VCD quality, Size: 930MB<br />
    <br />
    Hope you will like and if so please leave your comments...
    HTML:
    As I told most important part that number changes everytime so when a preg match it it doesn't recognize
    how can i solve a problem like this ?
     
    SNaRe, Jan 25, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    preg_match('~<div id="post_message_\d+">(.*?)</div>~s', $text, $match);
    
    echo $match[1];
    
    PHP:
    This should do it.
     
    nico_swd, Jan 26, 2008 IP
  3. sutuicom

    sutuicom Peon

    Messages:
    103
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    $str = '<div id="post_message_2052965">Hello Everyone<br /><br />There is a good movie for you all, a good creation from Mrinal Sen. <br />Cast:Utpal Dutt, Suhasini Muley, Shekar Chatterjee and others...<br />Story by Banafool<br />VCD quality, Size: 930MB<br /><br />Hope you will like and if so please leave your comments...</div>';
    echo strip_tags($str, '<br>');
    
    PHP:
     
    sutuicom, Jan 26, 2008 IP
  4. SNaRe

    SNaRe Well-Known Member

    Messages:
    1,132
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Nice ideas thanks to both of you
     
    SNaRe, Jan 26, 2008 IP