Pages

PHP strpos Function

The strpos function in PHP is used to find the position of the first match in a string. The syntax of thestrpos function is:
strpos ('string', 'match_pattern', [offset])
The optional offset parameter tells the function to start looking for the match after the offset-th character in the string. The value returned by the function still indicates the position of the first match relative to the entire string.
Let's take a look at the examples below:
Example 1
print strpos ('Hurrah Hurrah','Hur');
Result:
0
In this example, the match occurs at the very beginning of the string, hence the function returns 0.
Example 2
print strpos ('Hurrah Hurrah', 'Hur', 3);
Result:
7
The offset value of 3 means that we start looking for the match in position 3. From there, the first match occurs at position 7.

If you like this please Link Back to this article...



0 comments:

Post a Comment