The strcspn() function returns the number of characters find in a string before any part of the specified characters are found.
Syntax
strcspn(str,char,begin,len)
Parameters
str − The string to search
char − The char to search
begin − Where to begin in the string
len − The length of the string
Return
The strcspn() function returns the number of characters found in a string.
The following is an example −
Example
<?php echo strcspn("demo text","m"); ?>
The following is the output −
Output
2
Let us see another example −
Example
<?php echo strcspn("Demo text!!","e",0,4); ?>
The following is the output −
Output
1