You are here

function _asset_wizard_truncate in Asset 6

Same name and namespace in other branches
  1. 5.2 asset_wizard.module \_asset_wizard_truncate()
1 call to _asset_wizard_truncate()
asset_wizard_get_path in ./asset_wizard.module

File

./asset_wizard.module, line 574
Wizard-style interface for Asset.

Code

function _asset_wizard_truncate($text, $max_chars) {
  if (strlen($text) > $max_chars) {
    $text = substr($text, 0, $max_chars);
    $last_word = strrchr($text, ' ');
    if ($last_word == ' ') {
      $text = substr($text, 0, strlen($text) - 1) . '...';
    }
    else {
      $text = preg_replace('/' . preg_quote($last_word, '/') . '$/', '...', $text);
    }
  }
  return $text;
}