English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strpbrk() Function Usage and Example

PHP String String Function Manual

The strpbrk() function is used to search for any character in the specified character set within a string.

Syntax

string strpbrk ( string $haystack , string $char_list )

Definition and Usage

The string used to find specific characters. That is, find the characters in the char_list within the haystack string.

Return Value

 Returns a substring starting with the found character. If not found, returns FALSE.

Parameter

Serial NumberParameters and Description
1

haystack

Required. It specifies the first string to be searched

2

charlist

Required. It specifies the list of characters to be searched

Online Example

Try the following example, search for the character "hn" in the string and return the remaining part of the string starting from the first occurrence of the specified character:

<?php
//Find 'hn' in the string, 'n' is matched first, return the result
echo strpbrk("www.oldtoolbag.com","hn");
echo '<br>';
//Find the capital I letter in the string and return the result
echo strpbrk("input Input","I");
echo '<br>';
$text = 'This is a Simple text.';
// Output "is is a Simple text." because 'i' is matched first
echo strpbrk($text, 'mi');
echo '<br>';
// Output "Simple text." because characters are case-sensitive
echo strpbrk($text, 'S');   
?>
Test and see‹/›
oldtoolbag.com
Input
is is a Simple text.
Simple text.
PHP String String Function Manual