PHP | strpbrk() Function

The strpbrk() function is an in-built function in PHP which searches a string for any of the specified characters. This function returns the rest of the string from where it found the first occurrence of any of the specified character. In case if none of the characters are found, it returns false. This function is case-sensitive.

Syntax:

strpbrk( $string, $charlist)

Parameters: This function accepts two parameters as shown in the above syntax. Both the parameters are mandatory and must be supplied. All of these parameters are described below:

  • $string: This parameter specifies the string to be searched.
  • $charlist: This parameter specifies the characters to find.

Return Values: This function returns a string starting from the character found, or false if it is not found.

Examples:

Input : $string = "Geeks for Geeks!", $charlist = "ef"
Output : eeks for Geeks!
Explanation : 'e' is the first occurrence of the specified 
characters. This function will, therefore, output "eeks for Geeks!", 
because it returns the rest of the string from where it found
the first occurrence of 'e'.


Input : $string = "A Computer Science portal", $charlist = "tue"
Output : uter Science portal

Below programs will illustrate the strpbrk() function in PHP :

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo strpbrk("Geeks for Geeks!", "ef"); 
?>

chevron_right


Output:

eeks for Geeks!

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo strpbrk("A Computer Science portal", "tue"); 
?>

chevron_right


Output:

uter Science portal

Program 3: This program will illustrate the case-sensitivity of the function.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo strpbrk("A Computer Science portal", "c"); 
?>

chevron_right


Output:

cience portal

Reference:
http://php.net/manual/en/function.strpbrk.php



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.