[Solved] select 40 words from a string


Assuming words would be separated by spaces.

$words40=explode(" ", $string,41);
unset($words40[40]); // Discard the last element containing the remaining string

Of course this will fail on punctuation marks, but since you did not mention whether your string contains something to do with human readable languages or any other value, there is no reason to assume that it will be English Grammar, hence the answer.

Reference

7

solved select 40 words from a string