PHP strpbrk() Function

Definition

The strpbrk() function searches a string for any of the specified characters.

This function is case-sensitive.

Syntax

PHP strpbrk() Function has the following syntax.

strpbrk(string,charlist)

Parameter

ParameterIs RequiredDescription
stringRequired.String to search
charlistRequired.Characters to find

Return

PHP strpbrk() Function returns the string starting from the character found, otherwise it returns FALSE.

Example 1

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.

Example 2

Search illegal characters in user name


<?php/* w  w  w  .  ja va2s . c om*/
$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.

Example 3

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


<?php//from  w  w w  . j ava2s  .c o m
echo strpbrk("Hello world from java2s.com!","W");
echo "<br>";
echo strpbrk("Hello world!","w");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions