Home >Backend Development >PHP Tutorial >strpos strrchr strpbrk character search function in php

strpos strrchr strpbrk character search function in php

高洛峰
高洛峰Original
2016-11-29 13:32:111611browse

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.

Statement:
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