I recommend use DOMDocument class instead of regular expressions (is less resource consumer and more clear IMHO).
$content = '<div id="hey">
<div id="bla"></div>
</div>
<div id="hey">
<div id="bla"></div>
</div>';
$doc = new DOMDocument();
@$doc->loadHTML($content); // @ for possible not standard HTML
$xpath = new DOMXPath($doc);
$elements = $xpath->query("//div[@id='hey']");
/*@var $elements DOMNodeList */
for ($i=0;$i<$elements->length;$i++) {
/*@var $curr_element DOMElement */
$curr_element = $elements->item($i);
// Here do what you want with the element
var_dump($curr_element);
}
If you want to get the content from an URL you can use this line instead to fill the variable $content:
$content = file_get_contents('http://yourserver/urls/page.php');
idvalues should be uniquehttp://example.org/?field1=value1is a URL which could result from a GET form)ids are supposed to be single use. If you want to apply styles to multiple elements, you should be defining them to have the sameclass. Having multiple elements with the same ID can cause issues with JavaScript, forms, etc.