函数名称:strpos() 适用版本:PHP 4, PHP 5, PHP 7 函数描述:strpos() 函数用于查找字符串中第一次出现的位置,如果找到则返回第一次出现的位置,如果没有找到则返回 fa...
函数名称:strpos()
适用版本:PHP 4, PHP 5, PHP 7
函数描述:strpos() 函数用于查找字符串中第一次出现的位置,如果找到则返回第一次出现的位置,如果没有找到则返回 false。
语法:int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
参数:
返回值:
示例:
$myString = "Hello, world!";
$position = strpos($myString, "world");
if ($position !== false) {
echo "The word 'world' was found at position " . $position;
} else {
echo "The word 'world' was not found in the string.";
}
输出:
The word 'world' was found at position 7
注意事项: