How to obtain the last word of a string

后端 未结 8 2226
囚心锁ツ
囚心锁ツ 2020-12-03 19:53

we have that string:

\"I like to eat apple\"

How can I obtain the result \"apple\" ?

8条回答
  •  情歌与酒
    2020-12-03 20:34

    // Your string
    $str = "I like to eat apple";
    // Split it into pieces, with the delimiter being a space. This creates an array.
    $split = explode(" ", $str);
    // Get the last value in the array.
    // count($split) returns the total amount of values.
    // Use -1 to get the index.
    echo $split[count($split)-1];
    

提交回复
热议问题