Home > Article > Backend Development > How to use php strcspn function?
The strcspn() function is a built-in function in PHP. The syntax is strcspn(string,char,start,length). It is used to return the number of characters (including spaces) found in the string before any specified characters are found. . This function is case-sensitive.
php How to use strcspn() function?
The strcspn() function returns the number of characters (including spaces) searched in the string before any specified character is found.
Syntax:
strcspn(string,char,start,length)
Parameters:
● string: required. Specifies the string to search for.
●Char: required. Specifies the characters to search for.
● start: optional. Specifies the location to start the search.
●length: optional. Specifies the length of the string (how many characters to search for).
Return value: Returns the number of characters (including spaces) found in the string before any specified characters are found.
Let’s take a look at how to use the php strcspn() function through an example.
php strcspn() function example 1:
<?php echo strcspn("Hello php.cn!","p"); ?>
Output:
6
php strcspn() function example 1:
<?php echo strcspn("PHP is a good development language! I love PHP","good"); ?>
Output:
9
The above is the detailed content of How to use php strcspn function?. For more information, please follow other related articles on the PHP Chinese website!