Home > Article > Backend Development > PHP function strpbrk() that searches for any one of the specified characters in a string
Example
Search for the character "oe" in a string and return the remaining portion of the string starting from the first occurrence of the specified character:
<?php echo strpbrk("Hello world!","oe"); ?>
Definition and usage
strpbrk() function searches for any one of the specified characters in a string.
Note: This function is case-sensitive.
This function returns the remainder starting from the first occurrence of the specified character. If not found, returns FALSE.
Syntax
strpbrk(string,charlist)
Parameters | Description |
string | Required. Specifies the string to be searched for. |
charlist | Required. Specifies the characters to search for. |
Technical details
Return value: | Returns the character starting from the character being searched for string. If not found, returns FALSE. |
PHP version: | 5+ |
<?php echo strpbrk("Hello world!","W"); echo "<br>"; echo strpbrk("Hello world!","w"); ?>Example
/* STRPBRK.C */ #include <string.h> #include <stdio.h> void main( void ) { char string[100] = "The 3 men and 2 boys ate 5 pigs\n"; char *result; /* Return pointer to first 'a' or 'b' in "string" */ printf( "1: %s\n", string ); result = strpbrk( string, "0123456789" ); printf( "2: %s\n", result++ ); result = strpbrk( result, "0123456789" ); printf( "3: %s\n", result++ ); result = strpbrk( result, "0123456789" ); printf( "4: %s\n", result ); }Output:
1: The 3 men and 2 boys ate 5 pigs 2: 3 men and 2 boys ate 5 pigs 3: 2 boys ate 5 pigs 4: 5 pigs
The above is the detailed content of PHP function strpbrk() that searches for any one of the specified characters in a string. For more information, please follow other related articles on the PHP Chinese website!