text: Encrypt string with product of number of vowels and consonants in substring of size k | isVowel ( ) is a function that returns true for a vowel and false otherwise . ; function to Encrypt the dtring ; for each substring ; substring of size k ; counting number of vowels and consonants ; append product to answer . ; Driver Code
code: < ? php function isVowel ( $ c ) { return ( $ c == ' a ' $ c == ' e ' $ c == ' i ' $ c == ' o ' $ c == ' u ' ) ; } function encryptString ( $ s , $ n , $ k ) { $ countVowels = 0 ; $ countConsonants = 0 ; $ ans = " " ; for ( $ l = 0 ; $ l <= $ n - $ k ; $ l ++ ) { $ countVowels = 0 ; $ countConsonants = 0 ; for ( $ r = $ l ; $ r <= $ l + $ k - 1 ; $ r ++ ) { if ( isVowel ( $ s [ $ r ] ) == true ) $ countVowels ++ ; else $ countConsonants ++ ; } $ ans = $ ans . ( string ) ( $ countVowels * $ countConsonants ) ; } return $ ans ; } $ s = " hello " ; $ n = strlen ( $ s ) ; $ k = 2 ; echo encryptString ( $ s , $ n , $ k ) . " STRNEWLINE " ;