I am trying to get the last few words in a string. For the last word, I am using this:
$string = "Hallo dies ist ein extrem langer Text den ich gern gekuerz haette, leider bin ich selbst zu doof dafür und mach hier einen test.";
$pattern = '/[^ ]*$/';
preg_match($pattern, $string, $result);
echo "<br>The last word is:------ ". $result[0] ." ---------<br>";
It works fine, but I need the flexibility to get, say, the last 3 words.
I do not know how to change the pattern.