public static function get_attribute($tag, $attrname, $type = PARAM_RAW) {
        if (preg_match('/^<[^>]*\b' . $attrname . '="(.*?)"/is', $tag, $matches)) {
            return clean_param(htmlspecialchars_decode($matches[1]), $type);
        } else if (preg_match('~^<[^>]*\b' . $attrname . '[ />]"~is', $tag, $matches)) {
            // Some attributes may not have value, for example this is valid: <video controls>.
            return clean_param("true", $type);
        }
        return null;
    }