PHP strpos() Function

The strops() is in-built function of PHP. It is used to find the position of the first occurrence of a string inside another string or substring in a string.

Syntax:

ParameterDescriptionRequired/Optional
stringSpecify the string to search.Start
findSpecify the string to find.Required
startSpecify where to begin the search.Optional

This function will help us to find the numeric position of the first occurrence of needle in the haystack string

Note: The strops() function is case-sensitive and binary-safe.

Example 1

Output:

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

Example 2

Output:

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

Example 3

Output:

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

See Also:

strchr() : It is used to find the first occurrence of a string inside another string.

stscroll() : It is locale based string comparison.

strcmp() : It is binary safe string comparison.

Reference:

http://php.net/manual/en/function.strpos.php


Next TopicPHP String