code: public static function buildAttribString($attribs)
      {
          if (\is_string($attribs)) {
              return \rtrim(' '.\trim($attribs));
          }
          $attribPairs = array();
          foreach ($attribs as $k => $v) {
              if (\is_int($k)) {
                  $k = $v;
                  $v = true;
              }
              $k = \strtolower($k);
              if (\strpos($k, 'data-') === 0) {
                  $v = \json_encode($v);
                  $v = \trim($v, '"');
              } elseif (\is_bool($v)) {
                  $v = self::buildAttribBoolVal($k, $v);
              } elseif (\is_array($v) || $k === 'class') {
                  $v = self::buildAttribArrayVal($k, $v);
              }
              if (\array_filter(array(
                  $v === null,
                  $v === '' && \in_array($k, array('class', 'style'))
              ))) {
                  // don't include
                  continue;
              }
              $v = \trim($v);
              $attribPairs[] = $k.'="'.\htmlspecialchars($v).'"';
          }
          \sort($attribPairs);
          return \rtrim(' '.\implode(' ', $attribPairs));
      }
docs: Build attribute string
  
  Attributes will be sorted by name
  class & style attributes may be provided as arrays
  data-* attributes will be property json-encoded
  
  @param array $attribs key/values
  
  @return string
  @see    https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute