Home  >  Article  >  Backend Development  >  How to use php strspn function

How to use php strspn function

藏色散人
藏色散人Original
2019-02-11 10:57:112843browse

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.

How to use php strspn function

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn