Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php preg_match_all

Options
  • 08-10-2007 3:02pm
    #1
    Registered Users Posts: 3,401 ✭✭✭


    Hi Lads,

    I'm always trying to get information from one site and put it on another, like the bebo block my friends have, to make something quick and easy to output the contents of a bebo page? how do I get the contents of a certain part of a page into a php variable?

    Thanks
    Gary
    $content ="<tr><td valign=top align=middle width=90><a href=Profile.jsp?MemberId=272517134><img src=http://i2.bebo.com/035b/9/medium/2007/09/25/16/272517134a5647857940m.jpg border=0 width=90 height=90 vspace=1 hspace=5></a></td><td valign=top><img align=right vspace=3 src=http://s.bebo.com/img/luv.gif><a href=Profile.jsp?MemberId=272517134><b>Louise</b></a><br>DYING for sleep <img src=http://s.bebo.com/img/smiley_sad.gif> <img src=http://s.bebo.com/img/smiley_sad.gif> !!</td></tr>";
    
    preg_match_all("/(<b>Louise</b></a><br>)?(</td></tr>)/i", $content, $matches);
    
    echo $matches[1];
    


Comments

  • Registered Users Posts: 568 ✭✭✭phil


    You're not escaping forward slashes where you should be.

    If the HTML to match is
    <b> testing </b>
    

    Then the forward slash denoting the end of the b block needs to be escaped.

    Example:
    preg_match_all("/<b>(.*)<\/b><\/a><br>(.*)<\/td><\/tr>/i", $content, $matches);
    
    echo $matches[1][0] . " is " . $matches[2][0];
    


Advertisement