Home  >  Article  >  Backend Development  >  How to use php strcspn function?

How to use php strcspn function?

青灯夜游
青灯夜游Original
2019-05-30 10:55:452487browse

The strcspn() function is a built-in function in PHP. The syntax is strcspn(string,char,start,length). It is used to return the number of characters (including spaces) found in the string before any specified characters are found. . This function is case-sensitive.

How to use php strcspn function?

php How to use strcspn() function?

The strcspn() function returns the number of characters (including spaces) searched in the string before any specified character is found.

Syntax:

strcspn(string,char,start,length)

Parameters:

● string: required. Specifies the string to search for.

●Char: required. Specifies the characters to search for.

● start: optional. Specifies the location to start the search.

●length: optional. Specifies the length of the string (how many characters to search for).

Return value: Returns the number of characters (including spaces) found in the string before any specified characters are found.

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

php strcspn() function example 1:

<?php
echo strcspn("Hello php.cn!","p");
?>

Output:

6

php strcspn() function example 1:

<?php
echo strcspn("PHP is a good development language! I love PHP","good");
?>

Output:

9

The above is the detailed content of How to use php strcspn 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