加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

在PHP中strrpos找到最后一个字符位置?

发布时间:2020-12-13 22:34:32 所属栏目:PHP教程 来源:网络整理
导读:$string = "01234567890*****12345678901234567890*"; echo strrpos($string,'*****'); 为什么这会返回36而不是15? (click here测试) 07001 strrpos — Find the position of the last occurrence of a substring in a string 我错过了什么? 谢谢! 解:
$string = "01234567890*****12345678901234567890*";  
echo strrpos($string,'*****');

为什么这会返回36而不是15? (click here测试)

07001
strrpos — Find the position of the last occurrence of a substring
in a string

我错过了什么?
谢谢!

解:
使用下面的答案,我提供了PHP4替代方案

$haystack = "01234567890*****12345678901234567890*";  
$needle              = '*****';

$position = strlen($haystack) - strlen($needle) - strpos(strrev($haystack),strrev($needle));
echo $position; // 11
可能你正在使用PHP 4:

from php.net

针:如果needle不是字符串,则将其转换为整数并应用为字符的序数值.针只能是PHP 4中的单个字符.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读