strcspn() function in PHP


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

Syntax

strcspn(str,char,begin,len)

Parameters

  • str − The string to search

  • char − The char to search

  • begin − Where to begin in the string

  • len − The length of the string

Return

The strcspn() function returns the number of characters found in a string.

The following is an example −

Example

Live Demo

<?php
   echo strcspn("demo text","m");
?>

The following is the output −

Output

2

Let us see another example −

Example

Live Demo

<?php
   echo strcspn("Demo text!!","e",0,4); 
?>

The following is the output −

Output

1

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements