strspn
Calculate the length of the first substring in which all characters in the string exist in the specified character set
strspn()
function returns the number of characters specified in the charlist parameter in the string.
Tip: Please 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.
Returns the number of characters "kHlleo" contained in the string "Hello world!":
<?php echo strspn ( "Hello world!" , "kHlleo" ) ; ?>
Try it yourself
Returns the number of characters "abc" contained in the string "abcdefand":
<?php echo strspn ( "abcdefand" , "abc" ) ; ?>
Try it yourself
strspn ( string , charlist , start , length )
parameter | describe |
---|---|
string | Required. Specifies the string being searched. |
charlist | Required. Specifies the characters to be searched. |
start | Optional. Specifies where to start in the string. |
length | Optional. Defines the length of the string. |