PHP strspn () function
Examples
Returns the number of characters in the string "kHlleo" contains "Hello world!":
<?php
echo strspn("Hello world!","kHlleo");
?>
echo strspn("Hello world!","kHlleo");
?>
Running instance »
Definition and Usage
strspn () function returns the number of characters specified in the parameter charlist included in the string.
Tip: Use strcspn () function to return before finding any given character, the number of characters in the string to find.
Note: This function is binary safe.
grammar
strspn( string,charlist,start,length )
参数 | 描述 |
---|---|
string | 必需。规定被搜索的字符串。 |
charlist | 必需。规定要查找的字符。 |
start | 可选。规定在字符串的何处开始。 |
length | 可选。定义字符串的长度。 |
technical details
return value: | Returns the number of characters specified in the parameter charlist included in the string. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 4.3, add the start and length parameters. |
More examples
Example 1
Returns the number of characters that contains "abc" string "abcdefand" in:
<?php
echo strspn("abcdefand","abc");
?>
echo strspn("abcdefand","abc");
?>
Running instance »
PHP String Reference