English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP strcspn() Function Usage and Example

PHP String Character String Functions Manual

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

Syntax

strcspn(string,char,start,length)

Definition and Usage

It returns the number of characters found in the string before finding any part of the specified character.

Return Value

It returns the number of characters found in the string

Parameter

Serial NumberParameters and Description
1

string

It specifies the string to search for

2

char

It specifies the characters to search for

3

start

It specifies where to start in the string

4

length

It specifies the length of the string

Online Example

Try the following example, output in the string "www.oldtoolbag.com!" found the character "o" before the search character count:

<?php
 //in the string "www.oldtoolbag.com!" found the character "o" before the search character count
 echo strcspn("www.oldtoolbag.com!","o");
 
 echo '<br>';
 //The starting position is 0, the length of the search string is6.
 echo strcspn("Hello world!","w",0,6); 
?>
Test and see‹/›

Output Result

6
6

PHP String Character String Functions Manual