Created
August 31, 2010 09:56
-
-
Save laurynas/558816 to your computer and use it in GitHub Desktop.
Breaks long non-breaking string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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