How can I remove, with PHP, the last word from a String?
For example the string \"Hi, I\'m Gian Marco\" would become \"Hi, I\'m Gian\".
\"Hi, I\'m Gian Marco\"
\"Hi, I\'m Gian\"
The regular exprerssion can cause issues when the string has special characters. Why not simply go with this:
$input = "Hi, I'm Gian Marco"; $output = substr($input, 0, strrpos($input, " ")); echo $output;