Like:
The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt fox. Bright vixens jump; dozy fowl quack. Quick wafting zephyrs vex bold Jim. Quick zephyrs blow, vexing daft Jim.
(this is just sample text, the real one is much longer)
How can I get let’s say 5 words from this text?
I tried using explode(' ', $text); Then shuffle the array and pick 5 elements from it, but I get all the punctuation and other characters. I just want a-z characters. Also the words need to have at least 3 characters
You can use the built-in
str_word_countfor this:See it in action.
You can also use another way (such as
array_rand) of picking out random words from the$wordsarray if you are concerned about performance; this is just the most convenient.