-// $dom = new DOMDocument();
-//
-// @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
-//
-// $body = $dom->getElementsByTagName('body');
-//
-// $class = $dom->createAttribute('class');
-// $class->value = $cls;
-// $body->item(0)->appendChild($class);
-//
-// return $dom->saveHTML();
+ $dom = new DOMDocument();
+
+ @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
+
+ $body = $dom->getElementsByTagName('body');
+ if (!empty($body->length)) {
+ $body->item(0)->setAttribute('class', $cls);
+ } else {
+ $body = $dom->createElement("body");
+ $body->setAttribute('class', $cls);
+ $dom->appendChild($body);
+ }
+
+
+ return $dom->saveHTML();