code: public static function parseAttribString($str, $dataDecode = true)
      {
          $attribs = array();
          $regexAttribs = '/\b([\w\-]+)\b(?: \s*=\s*(["\'])(.*?)\\2 | \s*=\s*(\S+) )?/xs';
          \preg_match_all($regexAttribs, $str, $matches);
          $keys = \array_map('strtolower', $matches[1]);
          $values = \array_replace($matches[3], \array_filter($matches[4], 'strlen'));
          foreach ($keys as $i => $k) {
              $attribs[$k] = $values[$i];
              if (\in_array($k, self::$htmlBoolAttr)) {
                  $attribs[$k] = true;
              }
          }
          \ksort($attribs);
          foreach ($attribs as $k => $v) {
              if (\is_string($v)) {
                  $attribs[$k] = \htmlspecialchars_decode($v);
              }
              $isDataAttrib = \strpos($k, 'data-') === 0;
              if ($isDataAttrib && $dataDecode) {
                  $val = $attribs[$k];
                  $attribs[$k] = \json_decode($attribs[$k], true);
                  if ($attribs[$k] === null && $val !== 'null') {
                      $attribs[$k] = \json_decode('"'.$val.'"', true);
                  }
              }
          }
          return $attribs;
      }
docs: Parse string -o- attributes into a key=>value array
  
  @param string  $str        string to parse
  @param boolean $dataDecode (true) whether to json_decode data attributes
  
  @return array