I received three really helpful answers here:
Break up one line of text without any discernible break points in PHP
It appeared adding true as as option to wordwrap fixed the problem but it's breaking another function so badly I can't use it. The function is along the same vein as this issue and grabs long URLs and truncates the anchor text to "Short URL".
Any ideas why the wordwrap true addition breaks this ? I see any characters after the set limit of the URL printed after "Short URL" which is quite strange.
function long_links($stringa){
$m = preg_match_all('/(www\.|http:\/\/|https:\/\/)([^\s]+)/', $stringa, $match);
if ($m){ $links=$match[0];
for ($j=0;$j<$m;$j++){
$loco=$links[$j]; $len=strlen($loco);
if($len > 59){
$stringa = str_replace($loco,'<a href="'.$loco.'" title="'.$loco.'" target=_blank><i>Short Link</i></a>',$stringa);
}
}
return $stringa;
}
Why would this break $body = wordwrap($body, 83, "\n", true); echo $body; ?
An example of the spill over I see is:
*Short URL* conditions/products-and-services/bonus-bank/index.htm
EDIT following Martin's question
$body=long_links($body); $body = wordwrap($body, 83, "\n", true); echo $body;
Thanks again !