English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP strspn() Function Usage and Example

PHP String Function Manual

The strspn() function is used to return the number of characters in the string that contain the charlist parameter specified.

Syntax

strspn(string,charlist,start,length)

Definition and Usage

Returns the number of characters in the string that contain the charlist parameter specified.

Return Value

Returns the number of characters in the string that contain the charlist parameter specified; if the string is not found, it returns false

Parameter

Serial NumberParameters and Description
1

string

It specifies the string to be searched

2

length

Define the length of the string

3

start

It specifies where to start

4

charlist

Specify the character to be searched

Online Example

Try the following example to return the number of characters in the string "Hello world!" that contain the character "kHlleo":

<?php
  //Returns the number of characters in the string "Hello world!" that contain the character "kHlleo"
   echo strspn("Hello world!","kHlleo");
?>
Test and see‹/›

Output Result

5

PHP String Function Manual