I am currently working on a php project where I need to display a string up to a maximum of 100 characters but without splitting the word.
For example if I have the string
The quick brown fox jumped over the lazy dogs back
Say the 100th character is in the middle of ‘jumped’.
At the moment I am using substr($mystring, 0, 100)
This will then print
The quick brown fox jum
Instead in this case I would want to print
The quick brown fox
Is this possible to fix
The key is using strrpos to cut off at a space rather than the middle of a word.
Note: If the source for these strings uses a multibyte charset, e.g., UTF-8, you will want to use the multibyte equivalent functions.