/**
* Utilize RegEx to find the values of attributes given a specific element.
* Bug libxml2 2.6.28 and previous with regards to selecting attributes with colons in their name
*
* @param phpQueryObject $element Element to preform the search on
* @param string $element_name Name of the element to search for
* @param string $attribute_name Name of the attribute to search for
* @return string Value of the attribute for a given element, empty string otherwise
*
*/
function anno_get_attribute_value_regex($element, $element_name, $attribute_name)
{
$outer_html = $element->markupOuter();
// We only want to match everything in the media tag. Non greedy RegEx.
if (preg_match('/<' . $element_name . ' .*?>/', $outer_html, $element_match)) {
// $media_match[0] should now just contain the opening media tag and its attribute
// Match on attribute name where wrapping quotes can be any combination of ', ", or lack there of
if (preg_match('/ ' . $attribute_name . '=["\']?((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']?/', $element_match[0], $attribute_match)) {
// $matches[1] should match data contained in parenthesis above
if (isset($attribute_match[1])) {
return $attribute_match[1];
}
}
}
return '';
}