1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Regex problem

Discussion in 'PHP' started by linkinpark2014, Oct 19, 2009.

  1. #1
    hi
    I have this text:
    
    	<td class="alt1Active" align="left" id="[B]17[/B]">
    		<div>
    			<a href="http://example.com"><strong>[B]Some Text[/B]</strong></a>
    		</div>
    
    		<div class="smallfont">:: bla bla text ::</div>
    		
    		
    	</td>
    PHP:
    I want to get the number inside (id="17") and the text between <strong> tags.

    I tried this regex but im getting unrelated results:
    if(preg_match_all('/<td class="alt1Active" .* id="([0-9]*?)">.*<a href=".*">(.*?)<\/a><\/div>.*<\/td>/s', $data, $forumsIDs))
                          {
    			print_r($forumsIDs);
    		      }
    
    
    PHP:
    any help would be appreciated :)
    Reps will be awarded to anyone help..
     
    linkinpark2014, Oct 19, 2009 IP
  2. KastorPM

    KastorPM Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $contents = '<td class="alt1Active" align="left" id="[B]17[/B]">
            <div>
                <a href="http://example.com"><strong>[B]Some Text[/B]</strong></a>
            </div>
     
            <div class="smallfont">:: bla bla text ::</div>
            
        </td>';
        
    $pattern = "/<td[^\<]*id=\"([^\"]*)\"[^\<]*>\s*<div>\s*<a[^>]*><strong>([^<]*)<\/strong>/"; 
    $result = array();
     
     if (preg_match_all($pattern, $contents, $matches)) {
        foreach ($matches[1] as $key => $id) {
            $result[] = array(
                'id' => $id,
                'name' => $matches[2][$key]
            );
        }
     }
    
    PHP:
     
    KastorPM, Oct 19, 2009 IP
    linkinpark2014 likes this.
  3. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    its working like charm...
    thanx mate :)
     
    linkinpark2014, Oct 19, 2009 IP