Home > Article > Backend Development > How to use php strspn function
PHP strspn() function is used to calculate the length of the first substring in a string where all characters exist in the specified character set. Its syntax is strspn(string,charlist,start,length), and the parameter string is required. It refers to specifying the string to be searched; charlist is required and refers to specifying the characters to be searched.
#php How to use strspn function?
php strspn() function syntax
Function: Return the number of certain characters contained in the string
Syntax:
strspn(string,charlist,start,length)
Parameters:
string Required. Specifies the string to be searched for.
charlist Required. Specifies the characters to search for.
start Optional. Specifies where in the string to begin.
length Optional. Defines the length of the string.
Description:
Returns the number of characters specified in the charlist parameter contained in the string.
php strspn() function usage example 1
<?php echo strspn("Hello world!","kHlleo"); ?>
Output:
5
php strspn() function usage example 2
<?php echo strspn("PHP is a good development language! I love PHP","PHP"); ?>
Output:
3
This article is an introduction to the PHP strspn function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use php strspn function. For more information, please follow other related articles on the PHP Chinese website!