How to use php strcspn function

藏色散人
Release: 2023-04-05 06:54:01
Original
1942 people have browsed it

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

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

Output:

6
Copy after login

php strcspn() function usage example 2

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

Output:

9
Copy after login

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!

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