Latte\Runtime\Filters::htmlAttributes PHP Method

htmlAttributes() public static method

Returns element's attributes.
public static htmlAttributes ( $attrs ) : string
return string
    public static function htmlAttributes($attrs)
    {
        if (!is_array($attrs)) {
            return '';
        }
        $s = '';
        foreach ($attrs as $key => $value) {
            if ($value === NULL || $value === FALSE) {
                continue;
            } elseif ($value === TRUE) {
                if (static::$xhtml) {
                    $s .= ' ' . $key . '="' . $key . '"';
                } else {
                    $s .= ' ' . $key;
                }
                continue;
            } elseif (is_array($value)) {
                $tmp = NULL;
                foreach ($value as $k => $v) {
                    if ($v != NULL) {
                        // intentionally ==, skip NULLs & empty string
                        //  composite 'style' vs. 'others'
                        $tmp[] = $v === TRUE ? $k : (is_string($k) ? $k . ':' . $v : $v);
                    }
                }
                if ($tmp === NULL) {
                    continue;
                }
                $value = implode($key === 'style' || !strncmp($key, 'on', 2) ? ';' : ' ', $tmp);
            } else {
                $value = (string) $value;
            }
            $q = strpos($value, '"') === FALSE ? '"' : "'";
            $s .= ' ' . $key . '=' . $q . str_replace(['&', $q, '<'], ['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'], $value) . (strpos($value, '`') !== FALSE && strpbrk($value, ' <>"\'') === FALSE ? ' ' : '') . $q;
        }
        return $s;
    }