You can do it with regular expression. (see answer of Ahmed Ziani.)
However, in PHP you can also do it using some inbuilt function. see the code below
$text = "Hi, I'm Gian Marco";
$last_space_position = strrpos($text, ' ');
$text = substr($text, 0, $last_space_position);
echo $text;