Let's say I have the following sentence:
A quick brown fox jumped over a lazy dog.
However, I have a limit that only 25 characters are allowed in this sentence. This may leave me with something like:
A quick brown fox jum
However, this sentence does not make any grammatical sense, so I would prefer to find the last word that we can resolve by remaining in the press 25 char. This will give us something like:
A quick brown fox
which will be less than the 25 char limit, however it makes more grammatical meaning. I. The word is not broken, we have the maximum number of intelligible words, remaining within the limit.
How can I encode a function that will accept a string and a char limit such as 25, and if the string exceeds the limit, returns a string with the maximum number of words?
string php
Click upvote
source share