How to split a long string with PHP?
<p>I am currently looking into spliting a very long string that could contain HTML characteristics.</p>

<p>Once example is:</p>

<pre><code>Thiiiissssaaaveryyyylonnngggstringgg
</code></pre>

<p>For this I have used this function in the past:</p>

<pre><code>function split($sString, $iCount = 75)
{       
    $text = $sString;
 $new_text = '';
 $text_1 = explode('&gt;',$text);
 $sizeof = sizeof($text_1);
 for ($i=0; $i&lt;$sizeof; ++$i) {
        $text_2 = explode('&lt;',$text_1[$i]);
     if (!empty($text_2[0])) {

       $new_text .= preg_replace('#([^\n\r .]{'. $iCount .'})#iu', '\\1  ', $text_2[0]);
     }
     if (!empty($text_2[1])) {
         $new_text .= '&lt;' . $text_2[1] . '&gt;';
     }
 }
 return $new_text; }
</code></pre>

<p>The function works to pick up such characters and split them after X characters. The problem is when HTML or ASCII characters are mixed in there like this:</p>

<pre><code>Thissssiisss&lt;a href="#"&gt;lonnnggg&lt;/a&gt;sting&amp;#228;&amp;#228;&amp;#228;
</code></pre>

<p>I have been trying to figure out how to split this string above and to not count characters within HTML tags and to count each ASCII character as 1.</p>

<p>Any help would be great.</p>

<p>Thank you</p>
