PHP strcspn() 函数
PHP strcspn() 函数 实例 输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数: <?php echo strcspn("Hello world!","w"); ?> 定义和用法 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. 语法 strcspn( _string,char,start,length_ ) 参数 描述 _string_ 必需。规定要搜索的字符串。 _char_ 必需。规定要查找的字符。 _start_ 可选。规定开始查找的位置。 _length_ 可选。规定字符串的长度(搜索多少字符)。 技术细节 返回值: 返回在找到任何指定的字符之前,在字符串查找的字符数。 PHP 版本: 4+ 更新日志: 在 PHP 4.3 中,新增了 _start_ 和 _length_ 参数。 实例 1 使用所有的参数来输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数: <?php echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6. ?>
PHP strcspn() 函数
实例
输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数:
<?php echo strcspn("Hello world!","w"); ?>
定义和用法
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.
语法
strcspn( _string,char,start,length_ )
| 参数 | 描述 |
|---|---|
| _string_ | 必需。规定要搜索的字符串。 |
| _char_ | 必需。规定要查找的字符。 |
| _start_ | 可选。规定开始查找的位置。 |
| _length_ | 可选。规定字符串的长度(搜索多少字符)。 |
技术细节
| 返回值: | 返回在找到任何指定的字符之前,在字符串查找的字符数。 |
|---|---|
| PHP 版本: | 4+ |
| 更新日志: | 在 PHP 4.3 中,新增了 _start_ 和 _length_ 参数。 |
实例 1
使用所有的参数来输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数:
<?php echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6. ?>
交流与评论