PHP strcspn() Function


The strcspn() function is used to returns the number of characters including whitespaces found in a string only characters from specified character list.

Syntax
strcspn(string,char,start,length)
Parameters
  • string - (required)Specify the string to search.
  • char - (required)Specify the character to search.
  • start - (required)Specify where the string to start.
  • length - (required)Specify the length of the to string.
Example
<?php
    echo strcspn("Good Morning!","M");
?>

Output

5

Prev Next