public function addAttributes($html, array $attributes, $fallbackTagName = 'div', array $exclusiveAttributes = null)
{
if ($attributes === array()) {
return $html;
}
$rootElement = $this->getHtmlRootElement($html);
if ($rootElement === null || $this->elementHasAttributes($rootElement, $exclusiveAttributes)) {
return sprintf('<%s%s>%s</%s>', $fallbackTagName, $this->renderAttributes($attributes), $html, $fallbackTagName);
}
$this->mergeAttributes($rootElement, $attributes);
return preg_replace('/<(' . $rootElement->nodeName . ')\\b[^>]*>/xi', '<$1' . addcslashes($this->renderAttributes($attributes), '\\\\$') . '>', $html, 1);
}