function ctools_cleanstring_truncate

A friendly version of truncate_utf8.

Parameters

$string: The string to be truncated.

$length: An integer for the maximum desired length.

$separator: A string which contains the word boundary such as - or _.

Return value

The string truncated below the maxlength.

1 call to ctools_cleanstring_truncate()
ctools_cleanstring in includes/cleanstring.inc
Clean up a string value provided by a module.

File

includes/cleanstring.inc, line 193

Code

function ctools_cleanstring_truncate($string, $length, $separator) {
    if (drupal_strlen($string) > $length) {
        // Leave one more character.
        $string = drupal_substr($string, 0, $length + 1);
        // Space exists AND is not on position 0.
        if ($last_break = strrpos($string, $separator)) {
            $string = substr($string, 0, $last_break);
        }
        else {
            $string = drupal_substr($string, 0, $length);
        }
    }
    return $string;
}