Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

php preg_match_all

  • 08-10-2007 02:02PM
    #1
    Registered Users, Registered Users 2 Posts: 3,507 ✭✭✭


    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, Registered Users 2 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
Advertisement