我们有那个字符串:
"I like to eat apple"
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得结果"apple"?
Ric*_*ers 18
// 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];
Run Code Online (Sandbox Code Playgroud)
派对有点迟,但这也有效
$last = strrchr($string,' ');
Run Code Online (Sandbox Code Playgroud)
根据http://www.w3schools.com/php/func_string_strrchr.asp