Created
March 20, 2017 12:58
-
-
Save pepeloper/ea7dffb9567a3ac07705f0016ee4a6ac to your computer and use it in GitHub Desktop.
Revisions
-
pepeloper created this gist
Mar 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # Drupal Snippet In this snippet we will know how to trim any string in Drupal way using the [truncate_utf8](https://api.drupal.org/api/drupal/includes!unicode.inc/function/truncate_utf8/7.x) function ## Code ```php truncate_utf8($string, $max_length, $wordsafe = FALSE, $add_ellipsis = FALSE, $min_wordsafe_length = 1) ``` So for example we can do something like this: ```php $text = 'Here we have a large text saying nothing'; truncate_utf8($text, 12); // Here we have a l ``` ```php $text = 'Here we have a large text saying nothing'; truncate_utf8($text, 12, TRUE); // Here we have a ``` ```php $text = 'Here we have a large text saying nothing'; truncate_utf8($text, 12, TRUE, TRUE); // Here we have... ```