Home > Backend Development > PHP Problem > How to use php strspn function?

How to use php strspn function?

青灯夜游
Release: 2023-02-22 22:34:02
Original
2791 people have browsed it

The strspn() function is a built-in function in PHP. The syntax is strspn(string,charlist,start,length). It is used to return the number of characters specified in the charlist parameter in the string.

How to use php strspn function?

php How to use strspn() function?

strspn() function returns the number of characters specified in the charlist parameter in a 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.

Return value: Returns the number of characters specified in the charlist parameter contained in the string.

Let’s take a look at how to use the php strspn() function through an example.

php strspn() function example 1:

<?php
echo strspn("Hello world!","kHlleo");
?>
Copy after login

Output:

5
Copy after login

php strspn() function example 2:

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

Output:

3
Copy after login

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:
php
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