Open In App

PHP strpbrk() Function

Last Updated : 22 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




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


Output: 
 

eeks for Geeks!

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
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads