strspn()
This function will give you the length of a substring. The substring in question must consist of only the characters given as the second parameter.
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).
$str = "I-4762-blue"; $new = strspn( $str, '1234567890' ); // 0 $new = strspn( $str, '1234567890', 2 ); // 4 $new = strspn( $str, '1234567890', 2, 3 ); // 3
Here we’re ensuring that the string contains only the lowercase letters of the top row of the keyboard or space.
$str = 'retire you poor quiet writer'; $len = strspn( $str, 'qwertyuiop ' ); if( strlen( $str ) == $len ) { echo 'good'; }
See the manual entry for strspn()
