Skip to content
Related Articles

Related Articles

PHP | strpbrk() Function
  • Last Updated : 28 Mar, 2018

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:




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

Output:

eeks for Geeks!

Program 2:




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

Output:

uter Science portal

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




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

Output:

cience portal

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :