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 = "Beginner for Beginner!", $charlist = "ef"
Output : eeks for Beginner!
Explanation : 'e' is the first occurrence of the specified 
characters. This function will, therefore, output "eeks for Beginner!", 
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




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


Output: 
 

eeks for Beginner!

Program 2: 
 

php




<?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




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


Output: 
 

Science portal

Reference: 
<a target="_blank" rel="noopener noreferrer nofollow" href="http://php.net/manual/en/

function.strpbrk.php”>http://php.net/manual/en/function.strpbrk.php
 



Contact Us