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,