truncate_html

The truncate_html filter shortens a string to a specified length and ensures that the HTML does not get broken.

Arguments

The truncate_html filter has the following signature.

truncate_html(length, append)

Parameter Description
length

The length to truncate the string to. 

This argument is required.

To truncate a string to 100 characters you would do the following:

Since HTML is preserved, the number of characters may not be exactly the number of characters submitted but it will be very close.

If the string is less than the number of characters specified then no truncation occurs.

append

The character to append to the end of the truncated string. 

By default the character is … "…". If a value is not passed then the default character is used.

Examples:


Assignment

As with all filters, you can use the filter when assigning a value to another variable.

< Back to the list of filters