0
0
PHPprogramming~20 mins

Why string functions matter in PHP - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of string length function
What is the output of this PHP code?
$text = "Hello, world!";
echo strlen($text);
PHP
$text = "Hello, world!";
echo strlen($text);
A12
B13
C14
DError
Attempts:
2 left
💡 Hint
strlen counts all characters including punctuation and spaces.
Predict Output
intermediate
2:00remaining
Result of string replace
What will this PHP code output?
$str = "I love cats.";
echo str_replace("cats", "dogs", $str);
PHP
$str = "I love cats.";
echo str_replace("cats", "dogs", $str);
AError
BI love cats.
CI love cats.dogs
DI love dogs.
Attempts:
2 left
💡 Hint
str_replace replaces all occurrences of the search string.
Predict Output
advanced
2:00remaining
Output of string position function
What does this PHP code output?
$phrase = "Find the needle in the haystack.";
echo strpos($phrase, "needle");
PHP
$phrase = "Find the needle in the haystack.";
echo strpos($phrase, "needle");
A9
B10
CError
D-1
Attempts:
2 left
💡 Hint
strpos returns the position of the first character of the found substring, starting at 0.
Predict Output
advanced
2:00remaining
Behavior of substr with negative start
What will this PHP code output?
$text = "Programming";
echo substr($text, -3);
PHP
$text = "Programming";
echo substr($text, -3);
Aram
BProgramming
Cing
DError
Attempts:
2 left
💡 Hint
A negative start in substr counts from the end of the string.
Predict Output
expert
2:00remaining
Output of chained string functions
What is the output of this PHP code?
$input = "  Hello World  ";
echo strtoupper(trim($input));
PHP
$input = "  Hello World  ";
echo strtoupper(trim($input));
AHELLO WORLD
Bhello world
CDLROW OLLEH
DError
Attempts:
2 left
💡 Hint
trim removes spaces, strtoupper converts to uppercase.