Home  >  Article  >  Backend Development  >  PHP function strpbrk() that searches for any one of the specified characters in a string

PHP function strpbrk() that searches for any one of the specified characters in a string

黄舟
黄舟Original
2017-11-04 13:23:441426browse

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+
##More examples

Example 1

This function is case-sensitive ("W" and "w" output the same):

<?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 &#39;a&#39; or &#39;b&#39; 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn