Home > Backend Development > PHP Tutorial > 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

黄舟
Release: 2023-03-17 06:40:01
Original
1474 people have browsed it

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");
?>
Copy after login

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)
Copy after login
ParametersDescription
string Required. Specifies the string to be searched for.
charlistRequired. 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");
?>
Copy after login

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 );  
}
Copy after login

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
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template