Php/func string strcspn
来自菜鸟教程
PHP strcspn()函数
例
打印在“ Hello world!”中找到的字符数。在字符“ w”之前:
<?php
echo strcspn("Hello world!","w");
?>
定义和用法
strcspn()函数返回在找到指定字符的任何部分之前在字符串中找到的字符数(包括空格)。
Tip: 使用 strspn()
function表示在字符串中找到的字符数,该字符串仅包含指定字符列表中的字符。
注意: 此函数是二进制安全的。
句法
strcspn(string,char,start,length)
参数值
| 参数 | 描述 |
|---|---|
| string | 需要。指定要搜索的字符串 |
| char | 需要。指定要搜索的字符 |
| start | 可选的。指定字符串中的开始位置 |
| length | 可选的。指定字符串的长度(要搜索的字符串数) |
技术细节
| 返回值: | 返回在找到指定字符的任何部分之前在字符串中找到的字符数 |
| PHP版本: | 4+ |
| 更新日志: | The
start and length PHP 4.3中添加了参数 |
更多例子
例
使用所有参数打印在“ 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.
?>