/ Published in: PHP
URL: http://www.addedbytes.com
This function will add soft hyphens after every 3rd character in words of over 10 characters. It will not leave fewer than three characters following a soft hyphen.
Known bugs: Adds soft hyphens to URLs and within HTML tags.
Expand |
Embed | Plain Text
function SoftHyphens($text) { $return = ''; if ($wordLength > 10) { for ($i = 0; $i < $wordLength; $i++) { $return .= $words[$j][$i]; if ((($i % 3) == 2) && ($i < ($wordLength - 3)) && ($i > 0)) { $return .= '­'; } } } else { $return .= $words[$j]; } } return $return; }
Comments
Subscribe to comments
You need to login to post a comment.

Looks like this also has some issues with multi-byte characters. It counts them as several characters and adds a soft return in the middle of the character.
Thannks, I have strugged with long words in the past, and did not know of soft hyphens. Great function. Thanks.