PHP strpos()Function

PHP String 参考手册PHP String Reference Manual

Examples

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

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

Run example »

Definition and Usage

The strpos() function finds the position of the first occurrence of a string in another string (case-sensitive).

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

Note:This function is binary-safe.

Related functions:

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

Syntax

strpos(string,find,start)

Parameter Description
string Required. Specifies the string to be searched.
find

Required. Specifies the character to search for.

start Optional. Specifies the position to start the search.

Technical Details

Return value: Returns the position of the first occurrence of a string in another string, or FALSE if the string is not found.Note:String positions start at 0, not at 1.
PHP Version: 4+


PHP String 参考手册PHP String Reference Manual Other Extensions