src/Utility/Matching.php
public static function matchTag($tag, $subject, &$content = null, &$attrs = null) {
        $xml = new \XMLReader();
        $xml->xml($subject, 'UTF-8', LIBXML_NOERROR | LIBXML_ERR_NONE);

        // failed to parse => false
        if ($xml->read() === false) {
            return false;
        }

        // wrong tag => false
        if ($xml->name !== $tag) {
            return false;
        }

        $attrs = [];
        while ($xml->moveToNextAttribute()) {
            $attrs[$xml->name] = $xml->value;
        }

        $content = $xml->readInnerXML();

        return true;
    }
public static function matchTag($tag, $subject, &$content = null, &$attrs = null) {
        $xml = new \XMLReader();
        $xml->xml($subject, 'UTF-8', LIBXML_NOERROR | LIBXML_ERR_NONE);

        // failed to parse => false
        if ($xml->read() === false) {
            return false;
        }

        // wrong tag => false
        if ($xml->name !== $tag) {
            return false;
        }

        $attrs = [];
        while ($xml->moveToNextAttribute()) {
            $attrs[$xml->name] = $xml->value;
        }

        $content = $xml->readInnerXML();

        return true;
    }
public static function matchTag ( $ tag , $ subject , & $ content = null , & $ attrs = null ) { $ xml = new \ XMLReader ( ) ; $ xml -> xml ( $ subject , 'UTF-8' , LIBXML_NOERROR | LIBXML_ERR_NONE ) ; // failed to parse => false if ( $ xml -> read ( ) === false ) { return false ; } // wrong tag => false if ( $ xml -> name !== $ tag ) { return false ; } $ attrs = [ ] ; while ( $ xml -> moveToNextAttribute ( ) ) { $ attrs [ $ xml -> name ] = $ xml -> value ; } $ content = $ xml -> readInnerXML ( ) ; return true ; }
Check if the given input string match the given tag, and returns
an array of attributes if attrs is not null. This function does not
work for "singleton" tags.

@param string $tag Tag to match (e.g. 'a', 'div', 'span').
@param string $subject String within which to match the tag.
@param string $content Content within the tag, if one was found.
@param array $attrs Attributes of the tag, if one was found.

@return bool True if the given tag was found, false otherwize.
Check if the given input string match the given tag and returns an array of attributes if attrs is not null . This function does not work for singleton tags .