matched based on element id
Posted: Sat May 30, 2009 8:16 pm
Since element id's should be unique, I am trying to write an expression to match content between a pair of html tags only given the elements' id. Here is what I have come up with (it works):
Does anyone have any tips for optimizing?
Code: Select all
$html = '<div class="bar"><span class="foo" id="foo">bat</span></div>';
$id = "foo";
preg_match("#<([a-z]+)[^<>]*id=\"$id\"[^>]*>(.*)</\\1>#is", $html, $matches);
//matches bat