The strspn() function returns the number of characters found in the string that contains only characters from the charlist parameter.
PHP strspn() Function has the following syntax.
strspn(string,charlist,start,length)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to search |
charlist | Required. | Characters to find |
start | Optional. | Where in the string to start |
length | Optional. | Length of the string |
PHP strspn() Function returns the number of characters found in the string that contains only characters from the charlist parameter.
Return the number of characters found in the string "Hello world!" that contains the characters "Java2s.com":
<?php echo strspn("Hello world from java2s.com!","Java2s.com"); ?>
Return the number of characters found in the string "abcdefand" that contains the characters "abc":
<?php echo strspn("abcdefand","abc"); ?>