function views_trim_text

cis7 views.module views_trim_text($alter, $value)
cle7 views.module views_trim_text($alter, $value)
elmsmedia7 views.module views_trim_text($alter, $value)
icor7 views.module views_trim_text($alter, $value)
meedjum_blog7 views.module views_trim_text($alter, $value)
mooc7 views.module views_trim_text($alter, $value)

Trim the field down to the specified length.

Parameters

$alter:

  • max_length: Maximum lenght of the string, the rest gets truncated.
  • word_boundary: Trim only on a word boundary.
  • ellipsis: Show an ellipsis (...) at the end of the trimmed string.
  • html: Take sure that the html is correct.

$value: The string which should be trimmed.

1 call to views_trim_text()
views_handler_field::render_trim_text in sites/all/modules/ulmus/views/handlers/views_handler_field.inc
Trim the field down to the specified length.

File

sites/all/modules/ulmus/views/views.module, line 2391
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_trim_text($alter, $value) {
  if (drupal_strlen($value) > $alter['max_length']) {
    $value = drupal_substr($value, 0, $alter['max_length']);
    // TODO: replace this with cleanstring of ctools
    if (!empty($alter['word_boundary'])) {
      $regex = "(.*)\b.+";
      if (function_exists('mb_ereg')) {
        mb_regex_encoding('UTF-8');
        $found = mb_ereg($regex, $value, $matches);
      }
      else {
        $found = preg_match("/$regex/us", $value, $matches);
      }
      if ($found) {
        $value = $matches[1];
      }
    }
    // Remove scraps of HTML entities from the end of a strings
    $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));

    if (!empty($alter['ellipsis'])) {
      $value .= t('...');
    }
  }
  if (!empty($alter['html'])) {
    $value = _filter_htmlcorrector($value);
  }

  return $value;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.