PHP strcspn() 函数

2024 年 9 月 4 日 | 阅读 1 分钟

strcspn() 是 PHP 的预定义函数。它用于查找字符串中找到的第一个不匹配字符段的长度,或返回包含空格在内的字符数。

注意:此函数是二进制安全的。

语法

参数描述必需/可选
String指定要搜索的字符串。必需
字符指定要搜索的字符。必需
开始指定在字符串中开始的位置。可选
长度指定字符串的长度。可选

示例 1

输出

Your string is: Hello Javatpoint
By using strcspn() function:16

示例 2

输出

Your string is: Hello Javatpoint
By using strcspn() function:5

示例 3

输出

int(0)

示例 4

输出

int(0)

示例 5

输出

int(2)

示例 6

输出

int(2)

示例 7

输出

int(5)

示例 8

输出

int(4)

引用

https://php.ac.cn/manual/en/function.strcspn.php


下一主题PHP 字符串