The strpbrk() function searches a string for any of the specified characters.
This function is case-sensitive.
PHP strpbrk() Function has the following syntax.
strpbrk(string,charlist)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to search |
charlist | Required. | Characters to find |
PHP strpbrk() Function returns the string starting from the character found, otherwise it returns FALSE.
Search a string for the characters "oe", and return the rest of the string from where it found the first occurrence of the specified characters:
<?php
echo strpbrk("Hello world from java2s.com!","oe");
?>
The code above generates the following result.
Search illegal characters in user name
<?php//w w w.java 2s . c o m
$myString = "Hello, world from java2s.com!";
echo strpbrk( $myString, "abcdef" ); // Displays 'ello, world!'
echo strpbrk( $myString, "xyz" ); // Displays '' (false)
$username = "php@example.com";
if ( strpbrk( $username, "@!" ) ) {
echo "@ and ! are not allowed in usernames";
}
?>
The code above generates the following result.
This function is case-sensitive ("W" and "w" will not output the same):
<?php
echo strpbrk("Hello world from java2s.com!","W");
echo "<br>";
echo strpbrk("Hello world!","w");
?>
The code above generates the following result.