strpos() 函数是 PHP 中的一个字符串函数,用于查找一个字符串在另一个字符串中第一次出现的位置。
语法:
strpos(string $haystack, mixed $needle, int $offset = 0): int|false
参数:
$haystack
:要搜索的字符串。$needle
:要查找的字符串。$offset
(可选):从字符串的指定位置开始搜索,默认为 0。返回值:
示例:
$str = "Hello, world!";
$pos = strpos($str, "world");
if ($pos !== false) {
echo "The string 'world' was found at position: " . $pos;
} else {
echo "The string 'world' was not found.";
}
输出:
The string 'world' was found at position: 7
上一篇:php strpbrk() 函数在字符串中搜索指定字符中的任意一个。
下一篇:php strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站