strpos 函数在 php 中反向

2022-08-30 16:26:11

反向 strpos 函数

我想找到一种方法,我可以在其中找到反向字符位置。例如,最后一个“e”开始计数反向。

从示例

$string="Kelley";
$strposition = strpos($string, 'e');

它会给我位置1。


答案 1
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )

查找大海捞针串中最后一次出现的针的数字位置。

http://php.net/manual/en/function.strrpos.php


答案 2

你需要的是strrpos来查找字符串中子字符串最后一次出现的位置

$string = "Kelley";
$strposition = strrpos($string, 'e');
var_dump($strposition);

推荐