regex problem

Discussion in 'PHP' started by linkinpark2014, Aug 2, 2009.

  1. #1
    hi all
    i have this regex pattern:
    if(preg_match_all("/[(showthread.php\?t=(.*?)[\"\&])(t(.*?)\.html)]/", $search_topics, $topics_array))
    PHP:
    it simply should grab all topic numbers(ids) from any page i choose from different types of VBulletin boards..
    anyway, letme break it for u:
    some VB boards use this method to show topics:
    showthread.php?t=xxxxxxx
    and others use this method:
    t40190.html
    as u can see topic ID is merged with html file..
    my regex worx for first type only, i tried to make 1 pattern to match both links.
    [(showthread.php\?t=(.*?)[\"\&]) <-- used for first method and it works perfectly

    (t(.*?)\.html) <-- its not working]

    any help would be appreciated....
     
    linkinpark2014, Aug 2, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's your solution:

    if (preg_match_all('/(?:showthread\.php\?t=([0-9]+))|(?:t([0-9]+)\.html)/i', $search_topics, $topics_array)) {
    	echo "<pre>";
    	print_r($topics_array);
    }
    PHP:
     
    premiumscripts, Aug 3, 2009 IP
  3. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanx..
    I already found one, just to add incase somone wanted info..
     
    linkinpark2014, Aug 3, 2009 IP