Here's a version of Chunk Split I wrote that will not split html entities. Useful if you need to inject something in html (in my case, <wbr/> tags to allow for long text wrapping).
<?php
function HtmlEntitySafeSplit($html,$size,$delim)
{
$pos=0;
for($i=0;$i<strlen($html);$i++)
{
if($pos >= $size && !$unsafe)
{
$out.=$delim;
$unsafe=0;
$pos=0;
}
$c=substr($html,$i,1);
if($c == "&")
$unsafe=1;
elseif($c == ";")
$unsafe=0;
$out.=$c;
$pos++;
}
return $out;
}
?>