Skip to content

Instantly share code, notes, and snippets.

@dhargitai
Created August 7, 2013 22:18
Show Gist options
  • Save dhargitai/6179363 to your computer and use it in GitHub Desktop.
Save dhargitai/6179363 to your computer and use it in GitHub Desktop.
php: soft_cut_string
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