Klo yang ini kata, tanpa memperdulikan huruf besar atau kecil <?php function word_count($str) { $words = explode(" ", $str); $i = 0; foreach ($words as $word) { $i++; } return $i; } echo word_count("There ARE two WORDS in upper case in
Klo yang ini kata <?php function upper_count($str) { $words = explode(" ", $str); $i = 0; foreach ($words as $word) { if (strtoupper($word) === $word) { $i++; } } return $i; } echo upper_count("There ARE two WORDS
Klo yang ini kata <?php function upper_count($str) { $words = explode(" ", $str); $i = 0; foreach ($words as $word) { if (strtoupper($word) === $word) { $i++; } } return $i; } echo upper_count("There ARE two WORDS
Buat ngitung uppercase atau huruf kapital. function countUppercase($string) { return preg_match_all(/\b+\b/, $string) } countUppercase("Hello good Sir"); // 2