How to obtain the last word of a string

后端 未结 8 2235
囚心锁ツ
囚心锁ツ 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:53

    Get last word of string

    $string ="I like to eat apple";
    $las_word_start = strrpos($string, ' ') + 1; // +1 so we don't include the space in our result
    $last_word = substr($string, $last_word_start);
    echo $last_word // last word : apple

提交回复
热议问题