Home > Backend Development > PHP Tutorial > How to use php strspn function

How to use php strspn function

藏色散人
Release: 2023-04-05 06:52:02
Original
2891 people have browsed it

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)
Copy after login

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

Output:

5
Copy after login

php strspn() function usage example 2

<?php
echo strspn("PHP is a good development language! I love PHP","PHP");
?>
Copy after login

Output:

3
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template