How to Use strpbrk() Function in PHP 8.1 and 8.2 with Example?

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

Hello Friends Today, through this tutorial, I will tell you How to Use `strpbrk()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, the `strpbrk()` function is used to search a string for any of a set of characters. It returns the portion of the string starting from the first occurrence of any of the characters found in the given character set. Here’s how you can use `strpbrk()` in PHP 8.1 and 8.2 with an example:

<?php
// Example string
$string = "Hello World!";
// Characters to search for
$chars = "aeiou";
// Find the first occurrence of any vowel in the string
$result = strpbrk($string, $chars);
if ($result !== false) {
echo "First occurrence of any vowel found: " . $result;
} else {
echo "No vowels found in the string.";
}
?>

In this example, `strpbrk()` searches the `$string` for any of the characters specified in `$chars` (in this case, vowels). If it finds any of these characters, it returns the portion of the string starting from the first occurrence of any of these characters. If no matching character is found, it returns `false`.

Keep in mind that `strpbrk()` is case-sensitive. If you want to perform a case-insensitive search, you can use other string manipulation functions like `stristr()` or `stripos()` in combination with `strpbrk()`.