Trying to wrap the last 3 words in a tag
$str = \'Lorem ipsum dolor sit amet\';
$h2 = preg_replace(\'/^(?:\\w+\\s\\w+)(\\s\\w+)+/\', \'
Sabuj Hassan's treats numbers and _ as being part of a word as well, so use that if it makes sense.
Assuming "words" are letters delimited by a space:
$str = 'Lorem ipsum dolor sit amet';
$h2 = preg_replace('/([a-z]+ [a-z]+ [a-z]+)$/i', '$1', $str);
echo $h2;
If you want any non-whitespace considered a word then:
$h2 = preg_replace('/(\S+ \S+ \S+)$/', '$1', $str);