Count consonants in a string ( Iterative and recursive methods ) | Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code
< ? php function isConsonant ( $ ch ) { $ ch = strtoupper ( $ ch ) ; return ! ( $ ch == ' A ' $ ch == ' E ' $ ch == ' I ' $ ch == ' O ' $ ch == ' U ' ) && ord ( $ ch ) >= 65 && ord ( $ ch ) <= 90 ; } function totalConsonants ( $ str ) { $ count = 0 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) if ( isConsonant ( $ str [ $ i ] ) ) ++ $ count ; return $ count ; } $ str = " abc ▁ de " ; echo totalConsonants ( $ str ) ; return 0 ; ? >