src/Utility/Matching.php
public static function findTagOrAttribute($tag, $attrs, $subject) {
        $xml = new \XMLReader();
        $xml->xml($subject, 'UTF-8', LIBXML_NOERROR | LIBXML_ERR_NONE);
        // failed to parse => false
        if ($xml->read() === false) {
            return false;
        }

        if (!is_null($attrs) && !is_array($attrs)) {
            $attrs = [$attrs => null];
        }

        while ($xml->read()) {
            if (!is_null($tag) && $xml->name == $tag) {
                return true; // tag found
            }
            if (!is_null($attrs)) {
                foreach ($attrs as $attr => $attrValue) {
                    $value = $xml->getAttribute($attr);
                    if (!is_null($value)
                        && (is_null($attrValue) || $value == $attrValue)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
public static function findTagOrAttribute($tag, $attrs, $subject) {
        $xml = new \XMLReader();
        $xml->xml($subject, 'UTF-8', LIBXML_NOERROR | LIBXML_ERR_NONE);
        // failed to parse => false
        if ($xml->read() === false) {
            return false;
        }

        if (!is_null($attrs) && !is_array($attrs)) {
            $attrs = [$attrs => null];
        }

        while ($xml->read()) {
            if (!is_null($tag) && $xml->name == $tag) {
                return true; // tag found
            }
            if (!is_null($attrs)) {
                foreach ($attrs as $attr => $attrValue) {
                    $value = $xml->getAttribute($attr);
                    if (!is_null($value)
                        && (is_null($attrValue) || $value == $attrValue)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
public static function findTagOrAttribute ( $ tag , $ attrs , $ subject ) { $ xml = new \ XMLReader ( ) ; $ xml -> xml ( $ subject , 'UTF-8' , LIBXML_NOERROR | LIBXML_ERR_NONE ) ; // failed to parse => false if ( $ xml -> read ( ) === false ) { return false ; } if ( ! is_null ( $ attrs ) && ! is_array ( $ attrs ) ) { $ attrs = [ $ attrs => null ] ; } while ( $ xml -> read ( ) ) { if ( ! is_null ( $ tag ) && $ xml -> name == $ tag ) { return true ; // tag found } if ( ! is_null ( $ attrs ) ) { foreach ( $ attrs as $ attr => $ attrValue ) { $ value = $ xml -> getAttribute ( $ attr ) ; if ( ! is_null ( $ value ) && ( is_null ( $ attrValue ) || $ value == $ attrValue ) ) { return true ; } } } } return false ; }
Check if the given input string contains an element with the given
type name or attribute.

@param string $tag Tag name to search for, or null if not relevant.
@param string $attrs Array [name => value] for the attributes to search for, or null
if not relevant. `value` can be null if only the name should be looked.
@param string $subject String to search.

@return bool True if the given tag or given attribute is found.
Check if the given input string contains an element with the given type name or attribute .