tags * * @param DOMDocument $doc DOM document * * @return void */ private function transformDocumentLists(&$doc) { $ulList = $doc->getElementsByTagName('ul'); // Loop through each
tag while ($ulList->length > 0) { $listNode = $ulList->item(0); $newParaNode = $doc->createElement('p'); // Assemble text representation of list $paraText = ''; foreach($listNode->childNodes as $childNode) { $paraText .= '* '. $childNode->textContent ."\n"; } // Set
element's text $newTextNode = $doc->createTextNode($paraText); $newParaNode->appendChild($newTextNode); $listNode->parentNode->replaceChild($newParaNode, $listNode); } } /** * Transform description list-related tags, removing description * terms and enclosing the description text in
tags * * @param DOMDocument $doc DOM document * * @return void */ private function transformDocumentDescriptionLists(&$doc) { $termList = $doc->getElementsByTagName('dt'); // Loop through each
element while ($descriptionList->length > 0) { $descriptionNode = $descriptionList->item(0); // Create
node with description's text $newParaNode = $doc->createElement('p'); $newTextNode = $doc->createTextNode($descriptionNode->textContent); $newParaNode->appendChild($newTextNode); $descriptionNode->parentNode->replaceChild($newParaNode, $descriptionNode); } } /** * Transform break tags into newlines * * @param DOMDocument $doc DOM document * * @return void */ private function transformDocumentBreaks(&$doc) { $breakList = $doc->getElementsByTagName('br'); // Loop through each
and replace with text while($breakList->length) { $breakNode = $breakList->item(0); $newTextNode = $doc->createTextNode("\n"); $breakNode->parentNode->replaceChild($newTextNode, $breakNode); } } /** * Transform paragraph tags into newlines * * @param DOMDocument $doc DOM document * * @return void */ private function transformDocumentParasIntoNewlines(&$doc) { $paraList = $doc->getElementsByTagName('p'); // Loop through each
and replace with text while($paraList->length) { $paraNode = $paraList->item(0); $paraText = "\n". $paraNode->textContent ."\n"; $newTextNode = $doc->createTextNode($paraText); $paraNode->parentNode->replaceChild($newTextNode, $paraNode); } } /** * Remove text at the start of strings * * @param string $string text * @param string $substring text to remove * * @return string processed text */ private function removeFromStartOfString($string, $substring) { return substr($string, strlen($substring), strlen($string) - strlen($substring)); } } $script = new i18nRemoveHtmlTags(); $script->execute();