src/Control/HTTP.php
public static function findByTagAndAttribute($content, $attributes)
    {
        $regexes = [];

        foreach ($attributes as $tag => $attribute) {
            $regexes[] = "/<{$tag} [^>]*$attribute *= *([\"'])(.*?)\\1[^>]*>/i";
            $regexes[] = "/<{$tag} [^>]*$attribute *= *([^ \"'>]+)/i";
        }

        $result = [];

        if ($regexes) {
            foreach ($regexes as $regex) {
                if (preg_match_all($regex, $content, $matches)) {
                    $result = array_merge_recursive($result, (isset($matches[2]) ? $matches[2] : $matches[1]));
                }
            }
        }

        return count($result) ? $result : null;
    }
public static function findByTagAndAttribute($content, $attributes)
    {
        $regexes = [];

        foreach ($attributes as $tag => $attribute) {
            $regexes[] = "/<{$tag} [^>]*$attribute *= *([\"'])(.*?)\\1[^>]*>/i";
            $regexes[] = "/<{$tag} [^>]*$attribute *= *([^ \"'>]+)/i";
        }

        $result = [];

        if ($regexes) {
            foreach ($regexes as $regex) {
                if (preg_match_all($regex, $content, $matches)) {
                    $result = array_merge_recursive($result, (isset($matches[2]) ? $matches[2] : $matches[1]));
                }
            }
        }

        return count($result) ? $result : null;
    }
public static function findByTagAndAttribute ( $ content , $ attributes ) { $ regexes = [ ] ; foreach ( $ attributes as $ tag => $ attribute ) { $ regexes [ ] = "/<{$tag} [^>]*$attribute *= *([\"'])(.*?)\\1[^>]*>/i" ; $ regexes [ ] = "/<{$tag} [^>]*$attribute *= *([^ \"'>]+)/i" ; } $ result = [ ] ; if ( $ regexes ) { foreach ( $ regexes as $ regex ) { if ( preg_match_all ( $ regex , $ content , $ matches ) ) { $ result = array_merge_recursive ( $ result , ( isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : $ matches [ 1 ] ) ) ; } } } return count ( $ result ) ? $ result : null ; }
Search for all tags with a specific attribute, then return the value of that attribute in a
flat array.

@param string $content
@param array $attributes An array of tags to attributes, for example "[a] => 'href', [div] => 'id'"

@return array
Search for all tags with a specific attribute then return the value of that attribute in a flat array .