Overview of PHP strpos function
The strpos is in-built PHP function. The strpos function finds the position of the first occurrence of a string in another string. It returns the integer number as the position of the first occurrence of the string. The function strpos is case sensitive.
Note: The position starts from 0 and not 1.
- originalstring(required): The string in which we need to search for a string.
- searchstring(required): The string which needs to find in the originalstring
- position(optional): The position from where the search must begin. The default position is 0.
<?php $string = "We are at thecodetutorial"; $search = "thecodetutorial"; $positionafterfour = strpos($string, $search, 4); $positionfromstart = strpos($string, $search, 0); echo "Found at position(position from: 4): " . $positionafterfour."<br/>"; echo "Found at position from start string: " . $positionfromstart; exit; ?>
Found at position(position from: 4): 10
Found at position from start string: 10