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");
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions