PHP strspn() Function

Example

Return the number of characters in the string "Hello world!" that contain the character "kHlleo":

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

Run Instance

Definition and Usage

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

Tips:Please use strcspn() The function returns the number of characters in the string before finding any specified character.

Comments:This function is binary safe.

Syntax

strspn(string,charlist,start,length)
Parameters Description
string Required. Specify the string to be searched.
charlist Required. Specify the characters to be searched for.
start Optional. Specify where to start in the string.
length Optional. Define the length of the string.

Technical Details

Return Value: Return the number of characters in the string that contain charlist The number of characters specified in the parameter.
PHP Version: 4+
Update Log: In PHP 4.3, a new feature was added: start and length Parameters.

More Examples

Example 1

Return the number of characters in the string "abcdefand" that contain the character "abc":

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

Run Instance