PHP strspn()Functions
Examples
Returns the number of characters in the string "Hello world!" that contain the characters "kHlleo":
<?php
echo strspn("Hello world!","kHlleo");
?>
echo strspn("Hello world!","kHlleo");
?>
Run Example »
Definition and Usage
The strspn() function returns the number of characters found in the string that are contained in the charlist parameter.
Tip:Please usestrcspn()function to return the number of characters found in the string before any of the specified characters are found.
Note:This function is binary-safe.
Syntax
strspn(string,charlist,start,length)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to search. |
| charlist | Required. Specifies the characters to look for. |
| start | Optional. Specifies where in the string to start. |
| length | Optional. Defines the length of the string. |
Technical Details
| Return value: | Returns the number of characters in the string that containcharlistthe characters specified in the parameter. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP 4.3, thestartandlengthparameters were added. |
More Examples
Example 1
Returns the number of characters in the string "abcdefand" that contain the characters "abc":
<?php
echo strspn("abcdefand","abc");
?>
echo strspn("abcdefand","abc");
?>
Run Example »
PHP String Reference Manual Other Extensions