ellipsize()

ellipsize($str, $max_length[, $position = 1[, $ellipsis = '…']])

Parameters:
  • $str (string) – Input string
  • $max_length (int) – String length limit
  • $position (mixed) – Position to split at (int or float)
  • $ellipsis (string) – What to use as the ellipsis character
Returns:

Ellipsized string

Return type:

string

This function will strip tags from a string, split it at a defined maximum length, and insert an ellipsis.

The first parameter is the string to ellipsize, the second is the number of characters in the final string. The third parameter is where in the string the ellipsis should appear from 0 - 1, left to right. For example. a value of 1 will place the ellipsis at the right of the string, .5 in the middle, and 0 at the left.

An optional forth parameter is the kind of ellipsis. By default, … will be inserted.

Example:

$str = 'this_string_is_entirely_too_long_and_might_break_my_design.jpg';
echo ellipsize($str, 32, .5);

Produces:

this_string_is_e…ak_my_design.jpg
doc_CodeIgniter
2016-10-15 16:32:16
Comments
Leave a Comment

Please login to continue.