Home > Backend Development > PHP Tutorial > Character search function in php_PHP tutorial

Character search function in php_PHP tutorial

WBOY
Release: 2016-07-13 16:55:04
Original
974 people have browsed it

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"

will be output

/*

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

will be output

/*
*/
$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! ?.?"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631717.htmlTechArticlestristr() function finds the first occurrence of a string in another string. If successful, the remainder of the string (from the point of the match) is returned. If the string is not found...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template