It can be done like this:
<?php
$html = '<tbody><tr> <td>1.</td> <td><a href="something.php?y=US&id=197003">Some Name Here</a></td> <td>City, STATE</td> <td class="noWrap"></td> <td class="noWrap">123-456-7890</td></tr><tr class="altRow"> <td>2.</td> <td><a href="something.php?y=US&id=113762">Another Name</a></td> <td>City, STATE</td> <td class="noWrap"></td> <td class="noWrap">123-456-7890</td></tr>';
function get_id($data)
{
preg_match_all('/< *a[^>]*href *= *["\']?([^"\']*)/i', $data, $matches);
$result = array();
foreach($matches[1] as $id)
{
$r = explode('id=',$id);
$result[] = $r[1];
}
return $result;
}
print_r(get_id($html));
?>
Using preg_match_all to get all href in a tags and then searching for the right pattern, the constant, I set "id=" as constant in the explode() function but you can set also explode('something.php?y=US&id=',$id); if you want and you will get the same result:
Array
(
[0] => 197003
[1] => 113762
)
an array of IDs, bye :)
cereal
Veteran Poster
1,196 posts since Aug 2007
Reputation Points: 358
Solved Threads: 232
Skill Endorsements: 22
Question Answered as of 1 Year Ago by
cereal