Challenge - 5 Problems
Escape Sequence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of escape sequences in double-quoted strings
What is the output of the following PHP code?
PHP
<?php echo "Line1\nLine2\tTabbed"; ?>
Attempts:
2 left
💡 Hint
Remember that double-quoted strings interpret escape sequences like \n and \t.
✗ Incorrect
In PHP, double-quoted strings interpret escape sequences. \n creates a new line, and \t adds a tab space. So the output shows Line1, then a new line, then Line2 followed by a tab and 'Tabbed'.
❓ Predict Output
intermediate2:00remaining
Escape sequences in single-quoted strings
What will this PHP code output?
PHP
<?php echo 'Line1\nLine2\tTabbed'; ?>
Attempts:
2 left
💡 Hint
Single-quoted strings do not interpret most escape sequences except \' and \\.
✗ Incorrect
In PHP, single-quoted strings treat most escape sequences as literal characters. So \n and \t are printed as two characters \ and n or t, not as newline or tab.
❓ Predict Output
advanced2:00remaining
Using variable interpolation with escape sequences
What is the output of this PHP code?
PHP
<?php $name = "Anna"; echo "Hello, $name\nWelcome!"; ?>
Attempts:
2 left
💡 Hint
Double-quoted strings allow variable interpolation and escape sequences.
✗ Incorrect
In double-quoted strings, PHP replaces $name with its value 'Anna' and interprets \n as a newline. So the output is Hello, Anna followed by a new line and Welcome!
❓ Predict Output
advanced2:00remaining
Escape sequences with curly braces in variable interpolation
What does this PHP code output?
PHP
<?php $fruit = "apple"; echo "I have an {$fruit}s."; ?>
Attempts:
2 left
💡 Hint
Curly braces help PHP know where the variable name ends in strings.
✗ Incorrect
Using {$fruit}s tells PHP to replace $fruit with 'apple' and then add 's' after it, resulting in 'apples'.
🧠 Conceptual
expert2:30remaining
Understanding complex escape sequences in strings
Which option correctly describes the output of this PHP code snippet?
PHP
<?php echo "Path: C:\\Users\\John\nNew Line"; ?>
Attempts:
2 left
💡 Hint
Remember that \\ in double quotes prints a single backslash, and \n prints a newline.
✗ Incorrect
In PHP, double-quoted strings interpret \\ as a single literal backslash. So C:\\Users\\John becomes C:\Users\John, and \n becomes a newline. The output is two lines: 'Path: C:\Users\John' and 'New Line'.