函数名称:strcspn()
适用版本:PHP 4, PHP 5, PHP 7
函数描述:strcspn() 函数返回在字符串中查找给定字符集合中的字符所需的字符数。
用法:
int strcspn ( string $str1 , string $str2 [, int $start [, int $length ]] )
参数:
返回值: 返回在字符串中查找给定字符集合中的字符所需的字符数。
示例:
$str = "Hello World";
$charset = "Wrl";
$length = strcspn($str, $charset);
echo $length; // 输出 6
在上面的示例中,我们使用了strcspn()函数来查找字符串"Hello World"中字符集合"Wrl"中的字符所需的字符数。由于字符"W"出现在字符串的第6个位置,所以返回的结果是6。
注意事项: