How to remove last word from string?

Hello guys,

I’m cutting first 400 symbols from the text and I’d like to remove from the result string last word. I wonder is there built-in PHP function that will cut all letters until " " (space) symbol starting from the end of the string?

$b = substr($a, 0, strrpos($a, " "));


$b = preg_replace('~\\s+\\S+$~', '', $a);

will remove the last “word”. It would be perhaps simpler just to cut first, say, 40 words instead of 400 symbols. Search the forums, this has been discussed many times before.

Thank you very much for advice.

strrpos() works perfectly. :slight_smile: