PHP strspn() Function
Example
Return the number of characters contained in the string "Hello world!":
<?php echo strspn("Hello world!","kHlleo"); ?>
Definition and Usage
The strspn() function returns the number of characters contained in the string: charlist The number of characters specified in the parameter.
Tip:Please use strcspn() The function returns 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)
Parameter | 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 contained in the string: 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 Parameter. |
More Examples
Example 1
Return the number of characters contained in the string "abcdefand":
<?php echo strspn("abcdefand","abc"); ?>