PHP: How can I remove from String the last word?

后端 未结 6 1153
轻奢々
轻奢々 2021-02-05 21:39

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\".

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 22:24

    This code may help you :

    $str="Hi, I'm Gian Marco";
    
    $split=explode("",$str);
    $split_rem=array_pop($split);
    foreach ($split as $k=>$v)
    {
       echo $v.'';
    }
    

提交回复
热议问题