Current Location: Home> Function Categories> strspn

strspn

Calculate the length of the first substring in which all characters in the string exist in the specified character set
Name:strspn
Category:String
Programming Language:php
One-line Description:Returns the number of specific characters contained in the string.

Definition and usage

strspn() function returns the number of characters specified in the charlist parameter in the string.

Tip: Please use the strcspn() function to return the number of characters found in the string before any specified character is found.

Note: This function is binary safe.

Example

Example 1

Returns the number of characters "kHlleo" contained in the string "Hello world!":

 <?php
echo strspn ( "Hello world!" , "kHlleo" ) ;
?>

Try it yourself

Example 2

Returns the number of characters "abc" contained in the string "abcdefand":

 <?php
echo strspn ( "abcdefand" , "abc" ) ;
?>

Try it yourself

grammar

 strspn ( string , charlist , start , length )
parameter describe
string Required. Specifies the string being searched.
charlist Required. Specifies the characters to be searched.
start Optional. Specifies where to start in the string.
length Optional. Defines the length of the string.
Similar Functions
Popular Articles