Home >>PHP String Functions >PHP strspn() Function
PHP strspn() function is used to find the length of the initial segment of a string inside another string that contains only characters from the charlist parameter. It returns the total number of characters found in the string. It is case-sensitive & binary-safe.
Syntax:
strspn( $string, $charlist, $start, $length);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to search. |
charlist | This is a required parameter. This parameter contains the characters to find. |
start | This is an optional parameter. This parameter defines from where to start. |
length | This is an optional parameter. This parameter defines the length of the string. |
Here is an example of strspn() function in PHP:
<html> <body> <?php echo strspn("Hello Everyone.. Welcome to PHPTPOINT","…..Hello Everyone.."); ?> </body> </html>
Here is an another example of strspn() function in PHP:
<html> <body> <?php echo strspn("gfrandyhugndtyu","and",3,5); ?> </body> </html>