0
0
PHPprogramming~20 mins

Case conversion functions in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Case Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of strtolower and strtoupper
What is the output of this PHP code?
PHP
<?php
$text = "Hello World!";
echo strtolower($text) . " - " . strtoupper($text);
?>
Ahello world! - HELLO WORLD!
BHELLO WORLD! - hello world!
CHello World! - Hello World!
Dhello world! - hello world!
Attempts:
2 left
💡 Hint
strtolower converts all letters to lowercase, strtoupper converts all letters to uppercase.
Predict Output
intermediate
2: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));
?>
AHello WORLD! - Hello WORLD!
Bhello WORLD! - Hello WORLD!
CHello WORLD! - hELLO WORLD!
Dhello WORLD! - hELLO world!
Attempts:
2 left
💡 Hint
ucfirst makes first letter uppercase, lcfirst makes first letter lowercase.
Predict Output
advanced
2: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");
?>
AmÜnchEn ist schön
BMünchen Ist Schön
CMÜNCHEN IST SCHÖN
DMünchEn Ist Schön
Attempts:
2 left
💡 Hint
MB_CASE_TITLE capitalizes the first letter of each word correctly for UTF-8 strings.
Predict Output
advanced
2: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");
?>
AA
BError
CB
DC
Attempts:
2 left
💡 Hint
strcasecmp compares strings ignoring case and returns 0 if equal.
🧠 Conceptual
expert
3:00remaining
Why use mb_strtolower over strtolower?
Why should you use mb_strtolower instead of strtolower when working with UTF-8 strings in PHP?
Amb_strtolower correctly converts multibyte UTF-8 characters to lowercase, while strtolower only works reliably with ASCII characters.
Bmb_strtolower is faster than strtolower for all strings.
Cstrtolower converts strings to uppercase, mb_strtolower converts to lowercase.
Dmb_strtolower only works with ASCII, strtolower works with UTF-8.
Attempts:
2 left
💡 Hint
Think about characters like accented letters or non-English alphabets.