Skip to content

Instantly share code, notes, and snippets.

@laurynas
Created August 31, 2010 09:56
Show Gist options
  • Save laurynas/558816 to your computer and use it in GitHub Desktop.
Save laurynas/558816 to your computer and use it in GitHub Desktop.
Breaks long non-breaking string
<?php
/**
* Breaks long non-breaking string
*/
function break_nonbreaking($str, $max_length = 20, $breaker = ' ')
{
$max_length = (int)$max_length;
preg_match_all("/[^\s]{{$max_length},}/", $str, $m);
foreach ($m[0] as $x)
$str = str_replace($x, chunk_split($x, $max_length, $breaker), $str);
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment