Get the last word of a string

后端 未结 7 2295
时光说笑
时光说笑 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:59

    It depends on what you try to do (it is hard to understand from your description) but to get the last word from a string you can do:

    $split = explode(" ", $string);
    
    echo $split[count($split)-1];
    

    See How to obtain the last word of a string for more information.

提交回复
热议问题