slice

Parameter PositionTypeRequiredDefaultDescription
1integerNo80This determines the length of the resultant string.
2stringNo...This is the text to replace the middle portion of the string.
3booleanNotrueThis determines whether or not to truncate at a word boundary (false), or at the exact character (true).

This replaces the middle of a variable to achieve a string with a specific character length, default is 80. As an optional second parameter, you can specify a string of text that will replace the deleted segment. The characters in the string are included with the original truncation length. By default, slice will ignore word boundaries. If you want to split at a space, pass the optional third parameter of false.

Example 1. slice

{$url}
{$url|slice}
{$url|slice:20}
{$url|slice:20:""}
{$url|slice:20:"---"}

OUTPUT:

http://www.phpinsider.com/
http://www.phpinsider.com/
http://ww...der.com/
http://wwwider.com/
http://ww---der.com/