Returns the number of characters "kHlleo" contained in the string "Hello world!":
<?phpecho strspn("Hello world!","kHlleo");?>The strspn() function returns the number of characters specified in the charlist parameter in a string.
Tip: Use the strcspn() function to return the number of characters searched in a string before any specified character is found.
Note: This function is binary safe.
strspn( string,charlist,start,length )
parameter | describe |
---|---|
string | Required. Specifies the string to be searched for. |
charlist | Required. Specifies the characters to search for. |
start | Optional. Specifies where in the string to begin. |
length | Optional. Defines the length of the string. |
Return value: | Returns the number of characters specified in the charlist parameter in the string. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 4.3, new start and length parameters were added. |
Returns the number of characters "abc" contained in the string "abcdefand":
<?phpecho strspn("abcdefand","abc");?>