PHP strpos() 函数

2024 年 9 月 4 日 | 阅读 2 分钟

strops() 是 PHP 的内置函数。它用于在另一个字符串或子字符串中查找字符串的第一次出现的位置。

语法

参数描述必需/可选
string指定要搜索的字符串。开始
find指定要查找的字符串。必需
开始 (start)指定开始搜索的位置。可选

此函数将帮助我们找到 needle 在 haystack 字符串中第一次出现时的数字位置。

注意:strops() 函数区分大小写且是二进制安全的。

示例 1

输出

First string is: Hello Php
First string is: Hello Php javatpoint!
By using 'strpos()' function:

示例 2

输出

First string is: Hello php
First string is: Hello php javatpoint!
By using 'strpos()' function:6

示例 3

输出

The string 'Hello' was found in the string 'Hello PHP'
and exists at position 0

另请参阅

strchr() : 用于在另一个字符串中查找字符串的第一次出现。

stscroll() : 这是基于区域设置的字符串比较。

strcmp() : 这是二进制安全的字符串比较。

引用

https://php.ac.cn/manual/en/function.strpos.php


下一主题PHP 字符串