Advertisement
IDDQD-IDKFA

Untitled

May 20th, 2020
1,436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1.     protected static function cutFromDom($current, $length) {
  2.         $i = 0;
  3.         while($i < $current->childNodes->length) {
  4.             $node = $current->childNodes->item($i);
  5.             if($length > 0) {
  6.                 switch ($node->type) {
  7.                     case XML_TEXT_NODE:
  8.                     case XML_CDATA_SECTION_NODE:
  9.                         $node->textContent = mb_substr($node->textContent, 0, $length);
  10.                         $length -= mb_strlen($node->textContent);
  11.                         break;
  12.                     case XML_ELEMENT_NODE:
  13.                         $length = self::cutFromDom($node, $length);
  14.                         break;
  15.                 }
  16.                 $i++;
  17.             }
  18.             else {
  19.                 $current->removeChild($node);
  20.             }
  21.         }
  22.         return $length;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement