在字符串php中找到char的第二次出现 [英] find the second occurrence of a char in a string php
本文介绍了在字符串php中找到char的第二次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象一下我有这个字符串:
Imagine i have this string :
$info="portugal,alemanha,belgica,porto 1-0 alemanha, belgica 2-0";
我想知道第二个字符-"的位置,所以我想要2-0而不是1-0的结果.
I want to know the position of the 2nd char "-", so i want the result 2-0 and not the result 1-0.
我正在使用此功能,但它总是返回第一个位置,
I'm using this function, but it's always returning the first position,
$pos = strpos($info, '-');
有什么主意吗?谢谢
推荐答案
尝试一下
preg_match_all('/-/', $info,$matches, PREG_OFFSET_CAPTURE);
echo $matches[0][1][1];
这篇关于在字符串php中找到char的第二次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文