PHP instr() tutorial
An article from Learn PHP in 24 Hours
instr is a function used to find the first occurrence of a sub-string within a larger string.
Unlike ASP or VB, PHP does not use the terminology instr, but instead uses strpos.
Although named differently, strpos has the same basic functionality as instr.
strpos syntax:
int strpos (string $string1, mixed $string2 [, int $start = 0])
string1
String to search in
string2
The sub-string to find within string1
start
Optional. This is the character position to start at. This defaults to the first character if
omitted (start = 0 by default).
Return value:
Returns the integer position of the first character withing string1. FALSE is returned if
string2 is not found within string1.
What about some examples then?
$position = strpos("this is my example", "is");
will return the integer value 2.
Whereas,
$position = strpos("this is my example", "is", 3);
will return the integer value 5.
Other related functions you might enjoy!
strrpos() - Find position of last occurrence of a char in a string
stripos() - Find position of first occurrence of a case-insensitive string
strripos() – Find position of last occurrence of a case-insensitive string in a string
strrchr() - Find the last occurrence of a character in a string
substr() - Return part of a string
stristr() - Case-insensitive strstr
strstr() - Find first occurrence of a string
(function list from [Link])