Truncate String

Truncate a string to a specified length with ellipsis.

Code

General
strlen($str) > $length ? substr($str, 0, $length - 3) . '...' : $str;

Parameters

The string to truncate

Maximum length including ellipsis

Server

More PHP Snippets