I found the following PHP script create by webbiedave. Now my question is: How can I specify in strrpos() to search for space or dot? So if I set a maximum string length of 22 and my inout string is: Excluding the appended HTML tag, the output will be: If I have an input of: Excluding the appended HTML tag,
Tag: truncation
Truncate a string to first n characters of a string and add three dots if any characters are removed
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? Answer Update: Based on suggestion for checking length (and also ensuring similar lengths on trimmed and untrimmed strings): So you will get a string of max 13 characters;