Home > Article > Backend Development > How to use php strcspn function
PHP strcspn() function is used to output the number of characters to be searched before finding a certain character in the string. Its syntax is strcspn(string,char,start,length). The parameter string is required and refers to the string to be searched; char is required and specifies the character to be searched.
php How to use strcspn function?
php strcspn() function syntax
Function: Output the number of characters to find before finding a character in the string
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 where in the string to start searching.
length Optional. Specifies the length of the string (how many characters to search for).
Description:
Returns the number of characters (including spaces) searched in the string before any specified character is found.
php strcspn() function usage example 1
<?php echo strcspn("Hello php.cn!","p"); ?>
Output:
6
php strcspn() function usage example 2
<?php echo strcspn("PHP is a good development language! I love PHP","good"); ?>
Output:
9
This article is an introduction to the PHP strcspn function. I hope it will be helpful to friends in need!
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!