public static function replaceAttributes($xml, $tagName, callable $callback)
	{
		if (strpos($xml, '<' . $tagName) === false)
		{
			return $xml;
		}

		return preg_replace_callback(
			'((<' . preg_quote($tagName) . ')(?=[ />])[^>]*?(/?>))',
			function ($m) use ($callback)
			{
				return $m[1] . self::serializeAttributes($callback(self::parseAttributes($m[0]))) . $m[2];
			},
			$xml
		);
	}
public static function replaceAttributes($xml, $tagName, callable $callback)
	{
		if (strpos($xml, '<' . $tagName) === false)
		{
			return $xml;
		}

		return preg_replace_callback(
			'((<' . preg_quote($tagName) . ')(?=[ />])[^>]*?(/?>))',
			function ($m) use ($callback)
			{
				return $m[1] . self::serializeAttributes($callback(self::parseAttributes($m[0]))) . $m[2];
			},
			$xml
		);
	}
public static function replaceAttributes ( $ xml , $ tagName , callable $ callback ) { if ( strpos ( $ xml , '<' . $ tagName ) === false ) { return $ xml ; } return preg_replace_callback ( '((<' . preg_quote ( $ tagName ) . ')(?=[ />])[^>]*?(/?>))' , function ( $ m ) use ( $ callback ) { return $ m [ 1 ] . self :: serializeAttributes ( $ callback ( self :: parseAttributes ( $ m [ 0 ] ) ) ) . $ m [ 2 ] ; } , $ xml ) ; }
Replace the attributes of all tags of given name in given XML

@param  string   $xml      Original XML
@param  string   $tagName  Target tag's name
@param  callback $callback Callback used to process attributes. Receives the old attributes
as an array, should return the new attributes as an array
@return string             Modified XML
Replace the attributes of all tags of given name in given XML