strpbrk()

strpbrk() — Search a string for any of a set of characters.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

strpbrk() searches the string string for any of the characters in characters.

Signature

strpbrk(string $string, string $characters): string|false

Parameters

ParameterTypeWhat it takes
$stringstringThe string where characters is looked for.
$charactersstringThis parameter is case sensitive.

Return value

Returns a string starting from the character found, or false if it is not found.

Example

A runnable snippet:

$text = 'This is a Simple text.'; // this echoes "is is a Simple text." because 'i' is matched first echo strpbrk($text, 'mi'), PHP_EOL; // this echoes "Simple text." because chars are case sensitive echo strpbrk($text, 'S'), PHP_EOL;

Changelog

VersionChange
8.0.0Now throws a ValueError if characters is empty. Previously, an E_WARNING was raised and false was returned.

See also

strpos(), strstr(), preg_match()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page strpbrk() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.