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"
.
Advertisement
Answer
try with this :
$txt = "Hi, I'm Gian Marco"; $str= preg_replace('/Ww+s*(W*)$/', '$1', $txt); echo $str
out put
Hi, I'm Gian