How can I get the first n characters of a string in PHP? What\'s the fastest way to trim a string to a specific number of characters, and append \'...\' if needed?
This functionality has been built into PHP since version 4.0.6. See the docs.
echo mb_strimwidth('Hello World', 0, 10, '...'); // outputs Hello W...
Note that the trimmarker (the ellipsis above) are included in the truncated length.
trimmarker