25 public static function processHtml($content, callable $processor) {
26 $doc = new \DOMDocument();
27 $doc->loadHTML(
'<html>'.trim(mb_convert_encoding($content,
'HTML-ENTITIES',
'UTF-8')).
'</html>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
29 return trim(str_replace([
'<html>',
'</html>'],
'', $doc->saveHTML()));
40 foreach ($element->childNodes as $child) {
41 if ($child->nodeName == $elementName) {
55 $nextSibling = $element->nextSibling;
56 while ($nextSibling && $nextSibling->nodeType != $elementType) {
57 $nextSibling = $nextSibling->nextSibling;
69 $children = $element->childNodes;
70 foreach ($children as $child) {
71 $innerHTML .= $child->ownerDocument->saveXML( $child );
82 $doc = new \DOMDocument();
83 $doc->loadHTML(
'<body>'.trim(mb_convert_encoding($html,
'HTML-ENTITIES',
'UTF-8')).
'</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
84 $contentNode = $doc->getElementsByTagName(
'body')->item(0);
85 $contentNode = $element->ownerDocument->importNode($contentNode,
true);
86 $oldChildren = $element->childNodes;
87 foreach ($oldChildren as $child) {
88 $element->removeChild($child);
90 $newChildren = $contentNode->childNodes;
91 foreach ($newChildren as $child) {
92 $element->appendChild($child->cloneNode(
true));
104 $html = preg_replace(
"/(<br>\s*)+/",
"<br>", $html);
106 $html = preg_replace(
"/<p>(\s|<br>)*/",
"<p>", $html);
108 $html = preg_replace(
"/(\s|<br>)*<\/p>/",
"</p>", $html);
110 $html = preg_replace(
"/<p><\/p>/",
"", $html);
static setInnerHtml(\DOMElement $element, $html)
Set the inner html string of an element.
static getNextSiblingOfType(\DOMElement $element, $elementType)
Get the next sibling of the given element type.
static processHtml($content, callable $processor)
Process the given html fragment using the given function.
static removeEmptyLines($html)
Remove double linebreaks and empty paragraphs.
static getInnerHtml(\DOMElement $element)
Get the inner html string of an element.
static getChildNodesOfName(\DOMElement $element, $elementName)
Get the child nodes of a given element name.