Return to Snippet

Revision: 34605
at October 26, 2010 03:38 by newsok


Initial Code
function get_tag( $attr, $value, $xml, $tag=null ) {
  if( is_null($tag) )
    $tag = '\w+';
  else
    $tag = preg_quote($tag);

  $attr = preg_quote($attr);
  $value = preg_quote($value);

  $tag_regex = "/<(".$tag.")[^>]*$attr\s*=\s*".
                "(['\"])$value\\2[^>]*>(.*?)<\/\\1>/"

  preg_match_all($tag_regex,
                 $xml,
                 $matches,
                 PREG_PATTERN_ORDER);

  return $matches[3];
}

Initial URL


Initial Description


Initial Title
Matching an XHTML/XML tag with a certain attribute value

Initial Tags
xml

Initial Language
PHP