title: How to split long HTML content to multiple div without breaking words or formatting in php
body: <p>For now I got:</p>
  
  <pre><code>public static function splitContent($string, $lenght,  $maxCols){
          if (strlen($string)&lt;($lenght*$maxCols) &amp;&amp; strlen($string)&gt; $lenght){
              $string = wordwrap($string, $lenght, "||"); //assume your string doesn't contain `||`
              $parts = explode("||", $string);
              $result='';
              foreach ($parts as $part){
                  $result=$result.'&lt;div&gt;'.$part.'&lt;/div&gt;';
              }
              return $result;
          }
          return $string;
      }
  </code></pre>
  
  <p>and it works well when it comes to not breaking words but it often split HTML formatting tags like <code>&lt;span &lt;/div&gt;&lt;div&gt; style=....&gt;</code> how to prevent that? I see there is many problems like this when splitting html formatted string. Does anyone know about library to do it without hassle. it would be great if it would count only visible characters</p>