Created
August 7, 2013 22:18
-
-
Save dhargitai/6179363 to your computer and use it in GitHub Desktop.
php: soft_cut_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
function soft_cut_string($string, $length, $cut_string = '…') | |
{ | |
$new_string = $string; | |
if( mb_strlen($new_string) > $length ) | |
{ | |
$last_space_position = mb_strpos($new_string, " ", $length); | |
$new_string = mb_substr($new_string, 0, $last_space_position) . $cut_string; | |
} | |
return $new_string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment