truncate_utf8

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/unicode.inc, строка 233

Версии
5 – 6
truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE)

Безопасно обрезает кодированную в UTF-8 строку до указанного количества символов.

Параметры

$string Усекаемая строка.

$len Верхний предел длины возвращаемой строки.

$wordsafe Указывает, обрезать ли строку по последнему пробелу до указанной верхней границы. По умолчанию FALSE.

$dots Указывает, добавлять ли точки в конец строки. По умолчанию FALSE.

Возвращаемое значение

Усеченная строка.

▾ 12 функции вызывают truncate_utf8()

aggregator_parse_feed in modules/aggregator/aggregator.module
Parse a feed and store its items.
comment_admin_overview in modules/comment/comment.admin.inc
Конструктор формы; генерирует форму с кратким содержанием комментариев для администратора.
dblog_overview in modules/dblog/dblog.admin.inc
Коллбэк меню; выводит логи сообщений.
dblog_top in modules/dblog/dblog.admin.inc
Menu callback; generic function to display a page of the most frequent dblog events of a specified type.
node_teaser in modules/node/node.module
Создаёт анонс для тела ноды.
search_excerpt in modules/search/search.module
Возвращает отрывки из части текста, с выделением найденных ключевых слов. Используется для форматирования результатов поиска.<
_book_toc_recurse in modules/book/book.module
Рекурсивная вспомогательная функция для book_toc().
_comment_form_submit in modules/comment/comment.module
Prepare a comment for submission.
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table
_menu_parents_recurse in modules/menu/menu.module
Recursive helper function for menu_parent_options().
_search_index_truncate in modules/search/search.module
Helper function for array_walk in search_index_split.
_statistics_link in modules/statistics/statistics.module
It is possible to adjust the width of columns generated by the statistics module.

Код

<?php
function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) {

  if (drupal_strlen($string) <= $len) {
    return $string;
  }

  if ($dots) {
    $len -= 4;
  }

  if ($wordsafe) {
    $string = drupal_substr($string, 0, $len + 1); // leave one more character
    if ($last_space = strrpos($string, ' ')) { // space exists AND is not on position 0
      $string = substr($string, 0, $last_space);
    }
    else {
      $string = drupal_substr($string, 0, $len);
    }
  }
  else {
    $string = drupal_substr($string, 0, $len);
  }

  if ($dots) {
    $string .= ' ...';
  }

  return $string;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему