Easy Tutorial
❮ Func Array Rsort Func Zip Close ❯

PHP strspn() Function

PHP String Reference Manual

Example

Return the number of characters in the string "Hello world!" that are contained in the string "kHlleo":


Definition and Usage

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

Tip: Use the strcspn() function to return the number of characters in the string before any of the specified characters are found.

Note: This function is binary-safe.


Syntax

Parameter Description
string Required. Specifies the string to search.
charlist Required. Specifies the characters to find.
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 match any character specified in the charlist parameter.
PHP Version: 4+
--- ---
Changelog: Added start and length parameters in PHP 4.3.
--- ---

More Examples

Example 1

Return the number of characters in the string "abcdefand" that are contained in the string "abc":


❮ Func Array Rsort Func Zip Close ❯