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
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)
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)