PHP Tutorial - PHP strspn() Function






Definition

The strspn() function returns the number of characters found in the string that contains only characters from the charlist parameter.

Syntax

PHP strspn() Function has the following syntax.

strspn(string,charlist,start,length)

Parameter

ParameterIs Required Description
string Required. String to search
charlistRequired. Characters to find
start Optional.Where in the string to start
length Optional. Length of the string




Return

PHP strspn() Function returns the number of characters found in the string that contains only characters from the charlist parameter.

Example

Return the number of characters found in the string "Hello world!" that contains the characters "Java2s.com":

<?php
echo strspn("Hello world from java2s.com!","Java2s.com");
?>

Return the number of characters found in the string "abcdefand" that contains the characters "abc":

<?php
echo strspn("abcdefand","abc");
?>