PHP strspn() Function
Example
Return the number of characters from "kHlleo" contained in the string "Hello world!":
Run Example »
Definition and Usage
The strspn() function returns the number of characters in the string that are contained in the charlist parameter.
**Tip:** Please use strcspn() 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.
Syntax
strspn(
string,charlist,start,length
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to be searched. |
| charlist | Required. Specifies the characters to find. |
| start | Optional. Specifies where in the string to start. |
| length | Optional. Specifies the length of the string. |
Technical Details
| Return Value: | Returns the number of characters contained in the string from charlist the specified parameter. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP 4.3, the start and length parameter was added. |
More examples
Example 1
Return the number of characters "abc" contained in the string "abcdefand":
Run Example »
PHP String Reference Manual