Challenge - 5 Problems
Case Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of strtolower and strtoupper
What is the output of this PHP code?
PHP
<?php $text = "Hello World!"; echo strtolower($text) . " - " . strtoupper($text); ?>
Attempts:
2 left
💡 Hint
strtolower converts all letters to lowercase, strtoupper converts all letters to uppercase.
✗ Incorrect
The function strtolower converts all characters in the string to lowercase, and strtoupper converts all characters to uppercase. So the output is the lowercase version, then a dash, then the uppercase version.
❓ Predict Output
intermediate2:00remaining
Output of ucfirst and lcfirst
What is the output of this PHP code?
PHP
<?php $text = "hello WORLD!"; echo ucfirst($text) . " - " . lcfirst(strtoupper($text)); ?>
Attempts:
2 left
💡 Hint
ucfirst makes first letter uppercase, lcfirst makes first letter lowercase.
✗ Incorrect
ucfirst makes the first character uppercase and leaves the rest unchanged. strtoupper converts all letters to uppercase, then lcfirst makes the first letter lowercase again.
❓ Predict Output
advanced2:00remaining
Output of mb_convert_case with mixed UTF-8 string
What is the output of this PHP code using mb_convert_case with UTF-8 encoding?
PHP
<?php $text = "mÜnchEn ist schön"; echo mb_convert_case($text, MB_CASE_TITLE, "UTF-8"); ?>
Attempts:
2 left
💡 Hint
MB_CASE_TITLE capitalizes the first letter of each word correctly for UTF-8 strings.
✗ Incorrect
mb_convert_case with MB_CASE_TITLE converts the first character of each word to uppercase and the rest to lowercase, respecting UTF-8 characters like Ü and ö.
❓ Predict Output
advanced2:00remaining
Output of strcasecmp function
What is the output of this PHP code?
PHP
<?php $a = "Hello"; $b = "hello"; $result = strcasecmp($a, $b); echo $result > 0 ? "A" : ($result < 0 ? "B" : "C"); ?>
Attempts:
2 left
💡 Hint
strcasecmp compares strings ignoring case and returns 0 if equal.
✗ Incorrect
strcasecmp compares two strings case-insensitively. Since "Hello" and "hello" are equal ignoring case, it returns 0, so the output is "C".
🧠 Conceptual
expert3:00remaining
Why use mb_strtolower over strtolower?
Why should you use mb_strtolower instead of strtolower when working with UTF-8 strings in PHP?
Attempts:
2 left
💡 Hint
Think about characters like accented letters or non-English alphabets.
✗ Incorrect
strtolower only handles single-byte ASCII characters correctly. For UTF-8 strings with multibyte characters (like accented letters), mb_strtolower is needed to convert them properly to lowercase.