strcspn

int strcspn(string string, string mask) 

Returns the number of characters present in string before any part of mask is found.

Returns:

String

Description:

strcspn() returns the number of characters that occur between the start of string and the first occurrence of any character listed in mask .

strcspn() provides a simple way to parse strings and validate data. It is not commonly used in PHP—many other functions exist in the language that eclipse it in power and convenience.

Version:

PHP 3.0.3+, PHP 4+

See also:

To find the length of an initial substring containing only certain characters:

strspn() 

Other functions that count the number or occurrence of characters or strings within a string:

 count_chars() strlen() substr_count()  ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.