Latest web development tutorials

PHP strpos () function

PHP String Reference PHP String Reference

Examples

Find "php" in the position of the first occurrence of the string:

<?php
echo strpos("I love php, I love php too!","php");
?>

Running instance »

Definition and Usage

strpos () f function to find the position of a string in another string of the first occurrence (case-sensitive).

Note: strpos () function is case-sensitive.

Note: This function is binary safe.

Related functions:

  • strrpos () - Find the string in another string of the last occurrence (case-sensitive)
  • stripos () - Find the position of a string in another string of the first occurrence (case insensitive)
  • strripos () - Find the position of a string in another string of the last occurrence (case insensitive)

grammar

strpos( string,find,start )

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

technical details

return value: Returns the string in another string of the first occurrence of the string if not found returns FALSE. Note: The position of the string starting from 0, not 1.
PHP version: 4+


PHP String Reference PHP String Reference