Javatpoint Logo
Javatpoint Logo

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:

Parameter Description Required/Optional
String Specify the string to search. Required
Char Specifies the characters to search for. Required
Start Specify where in string start. Optional
Length Specify 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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA