Skip to content

Instantly share code, notes, and snippets.

@abhinavlal
Created December 17, 2011 15:27
Show Gist options
  • Save abhinavlal/1490488 to your computer and use it in GitHub Desktop.
Save abhinavlal/1490488 to your computer and use it in GitHub Desktop.
Add white space after 30 characters if there is no whitespace
function breakString($string){
$stringArray = explode(" ", $string);
if(is_array($stringArray)){
foreach($stringArray as $index => $substring){
if(strlen($substring) > 30){
$subsubStrings = str_split($substring, 30);
$stringArray[$index] = implode(" ", $subsubStrings);
}
}
}
$newString = implode(" ", $stringArray);
return $newString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment