定义和用法
strpos() 函数查找字符串在另一字符串中第一次出现的位置。
注释:strpos() 函数对大小写敏感。
注释:该函数是二进制安全的。
相关函数:
- stripos() - 查找字符串在另一字符串中第一次出现的位置(不区分大小写)
- strripos() - 查找字符串在另一字符串中最后一次出现的位置(不区分大小写)
- strrpos() - 查找字符串在另一字符串中最后一次出现的位置(区分大小写)
语法
<code class="language-php">strpos(string,find,start)</code>
参数 |
描述 |
string |
必需。规定要搜索的字符串。 |
find |
必需。规定要查找的字符串。 |
start |
可选。规定在何处开始搜索。 |
返回值
返回值: |
返回字符串在另一字符串中第一次出现的位置,如果没有找到字符串则返回 FALSE。
注释:字符串位置从 0 开始,不是从 1 开始。
|
PHP 版本: |
4+ |
实例
<code class="language-php"><?php //查找 "php" 在字符串中第一次出现的位置:
echo strpos("You love php, I love php too!","php");
?></code>
Stellungnahme:Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn