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..
$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: