How can a sentence be truncated to a certain number of words (NB. not letters)?
I thought to use split(" "), but then how do I count out words?
For example:
Javascript word count cut off => Javascript word count Want better search results? See our search tips! => Want better search
use PHP tokenizer function strtok() in a loop.
You can use split [MDN] and join [MDN].
"Want better search results? See our search tips".split(" ").splice(0,3).join(" ")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With