| Versions | |
|---|---|
| 6.x – 7.x | views_trim_text($alter, $value) |
Trim the field down to the specified length.
$alter
views/
<?php
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 .= '...';
}
}
if (!empty($alter['html'])) {
$value = _filter_htmlcorrector($value);
}
return $value;
}
?>