Hello Readers,
1> Both strchr and strrchr are the string functions.
2> strchr is an alias of strstr.
3> strchr returns the part of haystack string starting from and including the first occurrence of needle to the end of haystack and strrchr function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.
4> Syntax of strchr:
strchr(string_name, search_string, before_search)
Syntax of strrchr:
strrchr(string,char)
5> strchr function is case-sensitive. For a case-insensitive search, use stristr() function.
6> Example of strchr and strrchr
$s = 'This is a Web';//Here the given string
$first = strchr($s, 's');//First use the strchr
$last = strrchr($s, 's');//second use the strrchr
echo $first;//Print the strchr
output:
s is a Web
echo $last;//print the strrchr
output:
st
1 Comment(s)