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

How to use php strcspn function

藏色散人
藏色散人Original
2019-02-11 11:05:111926browse

PHP strcspn() function is used to output the number of characters to be searched before finding a certain character in the string. Its syntax is strcspn(string,char,start,length). The parameter string is required and refers to the string to be searched; char is required and specifies the character to be searched.

How to use php strcspn function

php How to use strcspn function?

php strcspn() function syntax

Function: Output the number of characters to find before finding a character in the string

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 where in the string to start searching.

length Optional. Specifies the length of the string (how many characters to search for).

Description:

Returns the number of characters (including spaces) searched in the string before any specified character is found.

php strcspn() function usage example 1

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

Output:

6

php strcspn() function usage example 2

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

Output:

9

This article is an introduction to the PHP strcspn function. I hope it will be helpful to friends in need!

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