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 php.net)
Back to Learn PHP in 24 Hours for more fun













GEEZ!I did a really long response to your post but my internet crapped out and I lost it all! Oh well, just wanted to say that it was a great post! Awesome!
well written blog. Im glad that I could find more info on this. thanks
Great information! I’ve been looking for something like this for a while now. Thanks!
Do you mind if I used a bit of your style.css for my own website? I would appreciate it! Thanks!
If you are referring to the WP theme look for the emoms theme by Wendy Piersall. Just look at the footer. Best of luck.
Hey man, was just browsing on the internet looking for some information and stumbled on your blog. I am impressed by the information that you have on this site. It shows how well you understand this subject. Marked this site, will come back for more. You, my friend, ROCK!!!
Hello!I am following your posts for quite a few days now. I have to say that it is very informative. It is added in my bookmarks and i will make sure that i will follow it frequently. Thanks for the nice posts . In addition, i honestly like your template and how you have structured your site . Could you the name of your template ? Cheers