Home >Backend Development >PHP Tutorial >strpos strrchr strpbrk character search function in php
strpos() function returns the position of the first occurrence of a string in another string. If the string is not found, it returns false.
Syntax: strpos(string,find,start), the code is as follows:
$str="hello world"; //Define string 1
$result=strpos($str,"ll"); The
strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string. If it fails, it returns false otherwise. Syntax: strrchr(string,char ), the code is as follows: $str="hello world"; //Define string 1 $result=strrchr($str,"o"); ; strpbrk() function searches for any one of the specified characters in the string. The function returns the remaining part starting from the first occurrence of the specified character. If it is not found, it returns false. Syntax: strpbrk(string , charlist), the code is as follows: $str="hello world"; //Define string 1 $result=strpbrk($str,"oe"); //Perform search operation echo $result; /Output results, ello world //Open source code phpfensi.com Tips and comments.Note: This function is case-sensitive.