Get the last word of a string

后端 未结 7 2309
时光说笑
时光说笑 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 05:09

    Here is another way to get the last word from a string

    $my_string = "fetch the last word from me";
     
    // Explode the string into an array
    $my_string = explode(" ", $my_string);
    
    // target the last word with end() function 
    $my_string = end($my_string);
    
    echo $my_string;
    

    Result me

提交回复
热议问题