PHP

PHP Menu

PHP

strcspn() Function - Definition, Syntax, Parameters, Examples

Definition

The strcspn() function returns the number of characters (including whitespaces) found in a string before any part of the specified characters are found.

Syntax

strcspn(string, char, start, length)

Parameters

Parameter Description
string Required. Specifies the string to search.
char Required. Specifies the characters to search for.
start Optional. Specifies where in string to start.
length Optional. Specifies the length of the string (how much of the string to search).

Example

<?php
echo strcspn("Welcome to PHP!", "e") . "<br>"; echo strcspn("Welcome to PHP!", "e", 8) . "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods