Home > Article > Backend Development > Character search function in php_PHP tutorial
stristr() function finds the first occurrence of a string within another string.
If successful, returns the rest of the string (from the point of the match). If the string is not found, returns false.
Grammar
stristr(string,search)
*/
$str="hello world"; //Define string
$result=stristr($str,"w"); //Perform search operation
echo $result; //Output the search results, "world"
/*
The stripos() function returns the position of the first occurrence of a string within another string.
If the string is not found, return false.
Grammar
stripos(string,find,start)
*/
$str="hello world"; //Define string
$result=stripos($str,"w"); //Perform search operation
echo $result; // Output the search results, 6
/*
*/
$str="hello world"; //Define string
$result=stripos($str,"l"); //Perform search operation
echo $result; // Output the search results, will return 2
/*
The strspn() function returns the number of specific characters contained in a string.
Grammar
strspn(string,charlist,start,length)
*/
$str="hello world"; //Define string
$result=strspn($str,"khlleo"); //Search for the length that meets the conditions
echo $result; // Output the length of the result, return 5
/*
*/
$str="hello world! ???"; //Define string
echo $str."
"; //Output the original string
echo convert_cyr_string($str,'w','a'); //Output the converted string "hello world! ?.?"