Current Location: Home> Function Categories> strcspn

strcspn

Get the length of the starting substring that does not match the mask
Name:strcspn
Category:String
Programming Language:php
One-line Description:Returns the number of characters found in the string before any part of some specified characters is found.

Definition and usage

strcspn() function returns the number of characters (including spaces) that are found on the string before any specified character is found.

Tip: Please use the strspn() function to return the number of characters in the string containing the specified character list.

Note: This function is binary safe.

Example

Example 1

Output the number of characters found before the character "w" is found in the string "Hello world!":

 <?php
echo strcspn ( "Hello world!" , "w" ) ;
?>

Try it yourself

Example 2

Use all parameters to output the number of characters that were found before the character "w" is found in the string "Hello world!":

 <?php
echo strcspn ( "Hello world!" , "w" , 0 , 6 ) ; // The start position is 0, and the length of the search string is 6.
?>

Try it yourself

grammar

 strcspn ( string , char , start , length )
parameter describe
string Required. Specifies the string to search.
char Required. Specifies the characters to be searched.
start Optional. Specifies where to start searching in the string.
length Optional. Specifies the length of the string (how many characters are searched for).
Similar Functions
Popular Articles