PHP strpbrk() Function (original) (raw)

Last Updated : 22 Jun, 2023

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,string, 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:

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

Input : string="GeeksforGeeks!",string = "Geeks for Geeks!", string="GeeksforGeeks!",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="AComputerScienceportal",string = "A Computer Science portal", string="AComputerScienceportal",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