Created
December 17, 2011 15:27
-
-
Save abhinavlal/1490488 to your computer and use it in GitHub Desktop.
Add white space after 30 characters if there is no whitespace
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
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