php – 如何获取字符串的最后一个单词
发布时间:2020-12-13 22:22:48 所属栏目:PHP教程 来源:网络整理
导读:我们有那个字符串: "I like to eat apple" 我怎样才能获得“苹果”的结果? 解决方法 // 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 t
|
我们有那个字符串:
"I like to eat apple" 我怎样才能获得“苹果”的结果? 解决方法// 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];
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |








