查找字符串中的确切单词位置 [英] Find the exact word position in string

查看:200
本文介绍了查找字符串中的确切单词位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个字符串.

$string = red,green,blue,yellow,black;

现在我有一个变量,它是我要搜索的单词的位置.

Now I have a variable which is the position of the word I am searching for.

$key = 2;

我想得到位置2的单词.在这种情况下,答案将是blue.

I want to get the word with the position of 2. In this case, the answer would be blue.

推荐答案

http://codepad.org/LA35KzEZ

$a = explode( ',', $string );
echo $a[ $key ];

这篇关于查找字符串中的确切单词位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆