strcspn()函数返回在找到任何指定的字符之前,在字符串中找到的字符数(包括空格)。
strcspn(string,char,start,length)
它返回在找到指定字符的任何部分之前在字符串中找到的字符数。
它返回字符串中找到的字符数
| 序号 | 参数和说明 |
|---|---|
| 1 | string 它指定要搜索的字符串 |
| 2 | char 它指定要搜索的字符 |
| 3 | start 它指定字符串中从哪里开始 |
| 4 | length 它指定字符串的长度 |
试试下面的实例,输出在字符串 "www.nhooo.com!" 中找到字符 "o" 之前查找的字符数:
<?php
//在字符串 "www.nhooo.com!" 中找到字符 "o" 之前查找的字符数
echo strcspn("www.nhooo.com!","o");
echo'<br>';
//起始位置为0,搜索字符串的长度为6。
echo strcspn("Hello world!","w",0,6);
?>测试看看‹/›输出结果
6 6