The strspn() function returns the number of characters found in the string that contains only characters from the charlist parameter.
int strspn ( string $subject , string $mask [, int $start [, int $length ]] )
Finds the length of the initial segment of subject that contains only characters from mask.
If start and length are omitted, then all of subject will be examined. If they are included, then the effect will be the same as calling strspn(substr($subject, $start, $length), $mask) (see substr for more information).
The line of code:
will assign 2 to $var, because the string "42" is the initial segment of subject that consists only of characters contained within "1234567890".
int(0)
int(2)
int(1)
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 |
Returns the length of the initial segment of subject which consists entirely of characters in mask.