config['aliases'][$elName][''])) ? $this->config['aliases'][$elName][''] : $this->config['prefix'] . ':' . $elName; if ($isEnd) { $this->parser->addEndTag($tagName, $pos, $len); continue; } // Test whether it's a self-closing tag or a start tag. // // A self-closing tag will become one start tag consuming all of the text followed by a // 0-width end tag. Alternatively, it could be replaced by a pair of 0-width tags plus // an ignore tag to prevent the text in between from being output $tag = (preg_match('/(<\\S+|[\'"\\s])\\/>$/', $m[0][0])) ? $this->parser->addTagPair($tagName, $pos, $len, $pos + $len, 0) : $this->parser->addStartTag($tagName, $pos, $len); $this->captureAttributes($tag, $elName, $m[3][0]); } } /** * Capture all attributes in given string * * @param Tag $tag Target tag * @param string $elName Name of the HTML element * @param string $str String containing the attribute declarations * @return void */ protected function captureAttributes(Tag $tag, $elName, $str) { $regexp = '/([a-z][-a-z0-9]*)(?>\\s*=\\s*("[^"]*"|\'[^\']*\'|[^\\s"\'=<>`]+))?/i'; preg_match_all($regexp, $str, $matches, PREG_SET_ORDER); foreach ($matches as $m) { /** * If there's no value, it's a boolean attribute and we generate a value equal * to the attribute's name, lowercased * * @link http://www.w3.org/html/wg/drafts/html/master/single-page.html#boolean-attributes */ $attrName = strtolower($m[1]); $attrValue = $m[2] ?? $attrName; // Use the attribute's alias if applicable if (isset($this->config['aliases'][$elName][$attrName])) { $attrName = $this->config['aliases'][$elName][$attrName]; } // Remove quotes around the value if ($attrValue[0] === '"' || $attrValue[0] === "'") { $attrValue = substr($attrValue, 1, -1); } $tag->setAttribute($attrName, html_entity_decode($attrValue, ENT_QUOTES, 'UTF-8')); } } }