This one is sort of the opposite of strspn() in that it finds the length of the substring which is not composed of the characters given.

It will not search through the string to find this substring but will start at the offset (default zero) and will continue only the specified number of characters (or to the end if no length is provided). Once it encounters any character in the string given as the second parameter, it stops and gives you the length of what it found.

$str = "I-4762-blue";
 
$len = strcspn( $str, '1234567890' );       // 2
$len = strcspn( $str, '1234567890', 4 );    // 0
$len = strcspn( $str, '1234567890', 6 );    // 5
$len = strcspn( $str, '1234567890', 6, 3 ); // 3