PHP strcspn() Function

The strcspn() is predefined function of PHP. It is used to find the length of initial segment or returns the number of characters including whitespaces found in a string.

Note: This function is binary-safe.

Syntax:

ParameterDescriptionRequired/Optional
StringSpecify the string to search.Required
CharSpecifies the characters to search for.Required
StartSpecify where in string start.Optional
LengthSpecify the length of string.Optional

Example 1

Output:

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

Example 2

Output:

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

Example 3

Output:

int(0)

Example 4

Output:

int(0)

Example 5

Output:

int(2)

Example 6

Output:

int(2)

Example 7

Output:

int(5)

Example 8

Output:

int(4)

References:

http://php.net/manual/en/function.strcspn.php


Next TopicPHP String




Latest Courses