【问题标题】:Get position of last character in a substring获取子字符串中最后一个字符的位置
【发布时间】:2015-05-11 23:56:41
【问题描述】:
$big = "new york city";
$small ="or";
$pos = strpos($big, $small);
echo $pos;

返回 5,但我希望它返回 6,即“r”的位置。提前致谢

【问题讨论】:

  • $pos = $pos + strlen($small) - 1
  • 加上子串的长度减1。应该很明显了。

标签: php string substring echo


【解决方案1】:
$big = "new york city";
$small ="or";
$pos = strpos($big, $small);
$pos = $pos + strlen($small) - 1;

echo $pos;

【讨论】:

  • 谢谢。 @kombian。我不知道为什么我没有想到这个解决方案
猜你喜欢
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-04
  • 2021-08-22
  • 1970-01-01
  • 2021-07-18
相关资源
最近更新 更多