Get the last word of a string

后端 未结 7 2302
时光说笑
时光说笑 2020-12-15 04:10

I have tried a few things to get a last part out I done this:

$string = \'Sim-only 500 | Internet 2500\';
preg_replace(\"Sim-Only ^([1-9]|[1-9][0-9]|[1-9][0-         


        
7条回答
  •  星月不相逢
    2020-12-15 04:50

    This should work for you:

    $str = "fetch the last word from me";
    $last_word_start = strrpos ( $str , " ") + 1;
    $last_word_end = strlen($str) - 1;
    $last_word = substr($str, $last_word_start, $last_word_end);
    

提交回复
热议问题