strcspn() 函數返回在找到任何指定的字符之前,在字符串查找的字符數(包括空格)。
提示: Use the strspn() function to the number of characters found in the string that contains only characters from a specified character list.
注釋: This function is binary-safe.
參數 | 描述 |
---|---|
string | 必需。規定要搜索的字符串。 |
char | 必需。規定要查找的字符。 |
start | 可選。規定開始查找的位置。 |
length | 可選。規定字符串的長度(搜索多少字符)。 |
返回值: | 返回在找到任何指定的字符之前,在字符串查找的字符數。 |
---|---|
PHP 版本: | 4+ |
更新日志: | 在 PHP 4.3 中,新增了 start 和 length 參數。 |
使用所有的參數來輸出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符數: