PHP strpos() Function

Example

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

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

Run Example

Definition and Usage

The strpos() function finds the first occurrence of a string within another string.

Note:The strpos() function is case-sensitive.

Note:This function is binary safe.

Related Functions:

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

Syntax

strpos(string,find,start)
Parameters Description
string Required. Specifies the string to be searched.
find Required. Specifies the string to be searched for.
start Optional. Specifies where to start the search.

Technical Details

Return Value:

Returns the position of the first occurrence of a string within another string. If the string is not found, FALSE is returned.

Note:String positions start from 0, not from 1.

PHP Version: 4+