public static function removeTag($xml, $tagName, $nestingLevel = 0)
	{
		if (strpos($xml, '<' . $tagName) === false)
		{
			return $xml;
		}

		$dom   = self::loadXML($xml);
		$xpath = new DOMXPath($dom);
		$query = '//' . $tagName . '[count(ancestor::' . $tagName . ') >= ' . $nestingLevel . ']';
		$nodes = $xpath->query($query);
		foreach ($nodes as $node)
		{
			$node->parentNode->removeChild($node);
		}

		return self::saveXML($dom);
	}
public static function removeTag($xml, $tagName, $nestingLevel = 0)
	{
		if (strpos($xml, '<' . $tagName) === false)
		{
			return $xml;
		}

		$dom   = self::loadXML($xml);
		$xpath = new DOMXPath($dom);
		$query = '//' . $tagName . '[count(ancestor::' . $tagName . ') >= ' . $nestingLevel . ']';
		$nodes = $xpath->query($query);
		foreach ($nodes as $node)
		{
			$node->parentNode->removeChild($node);
		}

		return self::saveXML($dom);
	}
public static function removeTag ( $ xml , $ tagName , $ nestingLevel = 0 ) { if ( strpos ( $ xml , '<' . $ tagName ) === false ) { return $ xml ; } $ dom = self :: loadXML ( $ xml ) ; $ xpath = new DOMXPath ( $ dom ) ; $ query = '//' . $ tagName . '[count(ancestor::' . $ tagName . ') >= ' . $ nestingLevel . ']' ; $ nodes = $ xpath -> query ( $ query ) ; foreach ( $ nodes as $ node ) { $ node -> parentNode -> removeChild ( $ node ) ; } return self :: saveXML ( $ dom ) ; }
Remove all tags at given nesting level

@param  string  $xml          Intermediate representation
@param  string  $tagName      Tag's name (case-sensitive)
@param  integer $nestingLevel Minimum nesting level
@return string                Updated intermediate representation
Remove all tags at given nesting level