在php中反向的strpos函数

Tap*_*101 17 php string strpos

strpos功能反向

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

从例子

$string="Kelley";
$strposition = strpos($string, 'e');
Run Code Online (Sandbox Code Playgroud)

它会给我一个位置1.

Man*_*ert 29

int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
Run Code Online (Sandbox Code Playgroud)

Find the numeric position of the last occurrence of needle in the haystack string.

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


Gui*_*nto 8

strripos并将长度strrpos添加$needle到结果中,例如:

<?php
$haystack = '/test/index.php';
$needle   = 'index.php';

echo strrpos($haystack, $needle);//output: 6
Run Code Online (Sandbox Code Playgroud)

另一种方法是用于strrev从末尾检索位置,例如:

<?php
$haystack = 'Kelley';
$needle   = 'e';

echo strpos(strrev($haystack), strrev($needle));//Output: 1
Run Code Online (Sandbox Code Playgroud)


Bab*_*aba 6

What you need is strrpos to find the position of the last occurrence of a substring in a string

$string = "Kelley";
$strposition = strrpos($string, 'e');
var_dump($strposition);
Run Code Online (Sandbox Code Playgroud)


tob*_*spr 5

尝试这个:

strrpos()
Run Code Online (Sandbox Code Playgroud)

希望有帮助。