阅读量:2
strrpos() 是 PHP 中的一个字符串函数,用于查找一个字符串在另一个字符串中最后一次出现的位置。函数原型如下:
strrpos(string $haystack, string $needle, int $offset = 0): int
参数说明:
$haystack:必需,要在其中搜索$needle的字符串。$needle:必需,要在$haystack中搜索的字符串。$offset(可选):必需,从该偏移量开始搜索$needle。默认值为 0,表示从字符串的开头开始搜索。
返回值:
- 返回
$needle在$haystack中最后一次出现的位置的索引。如果未找到,则返回false。
示例:
$haystack = "Hello, I am a PHP developer.";
$needle = "PHP";
// 从字符串的开头开始搜索
$position = strrpos($haystack, $needle);
if ($position !== false) {
echo "The last occurrence of '{$needle}' is at position: {$position}.";
} else {
echo "'{$needle}' not found in the string.";
}
// 从字符串的第 10 个字符开始搜索
$position = strrpos($haystack, $needle, 10);
if ($position !== false) {
echo "The last occurrence of '{$needle}' starting from position 10 is at position: {$position}.";
} else {
echo "'{$needle}' not found in the string starting from position 10.";
}
?>
输出:
The last occurrence of 'PHP' is at position: 27.
The last occurrence of 'PHP' starting from position 10 is at position: 38.
以上就是关于“php strrpos怎样使用”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm