- Optionally show dots after truncation. TODO: update user.module to take advantage of this.

4.7.x
Dries Buytaert 2005-07-06 14:20:11 +00:00
parent 02460ed9d8
commit 2c2d981e86
1 changed files with 3 additions and 3 deletions

View File

@ -1831,7 +1831,7 @@ function drupal_convert_to_utf8($data, $encoding) {
* @return * @return
* The truncated string. * The truncated string.
*/ */
function truncate_utf8($string, $len, $wordsafe = FALSE) { function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) {
$slen = strlen($string); $slen = strlen($string);
if ($slen <= $len) { if ($slen <= $len) {
return $string; return $string;
@ -1840,10 +1840,10 @@ function truncate_utf8($string, $len, $wordsafe = FALSE) {
while (($string[--$len] != ' ') && ($len > 0)) {}; while (($string[--$len] != ' ') && ($len > 0)) {};
} }
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) { if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
return substr($string, 0, $len); return substr($string, 0, $len) . ($dots ? ' ...' : '');
} }
while (ord($string[--$len]) < 0xC0) {}; while (ord($string[--$len]) < 0xC0) {};
return substr($string, 0, $len); return substr($string, 0, $len) . ($dots ? ' ...' : '');
} }
/** /**