0
0
PHPprogramming~20 mins

Escape sequences in strings in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Escape Sequence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of escape sequences in double-quoted strings
What is the output of the following PHP code?
PHP
<?php
echo "Line1\nLine2\tTabbed";
?>
ALine1\nLine2\tTabbed
BLine1 Line2 Tabbed
C
Line1
Line2	Tabbed
DLine1\nLine2 Tabbed
Attempts:
2 left
💡 Hint
Remember that double-quoted strings interpret escape sequences like \n and \t.
Predict Output
intermediate
2:00remaining
Escape sequences in single-quoted strings
What will this PHP code output?
PHP
<?php
echo 'Line1\nLine2\tTabbed';
?>
A
Line1
Line2	Tabbed
BLine1\nLine2\tTabbed
CLine1 Line2 Tabbed
DLine1\nLine2 Tabbed
Attempts:
2 left
💡 Hint
Single-quoted strings do not interpret most escape sequences except \' and \\.
Predict Output
advanced
2:00remaining
Using variable interpolation with escape sequences
What is the output of this PHP code?
PHP
<?php
$name = "Anna";
echo "Hello, $name\nWelcome!";
?>
A
Hello, $name
Welcome!
BHello, $name\nWelcome!
CHello, Anna\nWelcome!
D
Hello, Anna
Welcome!
Attempts:
2 left
💡 Hint
Double-quoted strings allow variable interpolation and escape sequences.
Predict Output
advanced
2: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.";
?>
AI have an apples.
BI have an apple s.
CI have an {$fruit}s.
DI have an $fruits.
Attempts:
2 left
💡 Hint
Curly braces help PHP know where the variable name ends in strings.
🧠 Conceptual
expert
2: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";
?>
A
Path: C:\Users\John
New Line
BPath: C:\\Users\\John\nNew Line
C
Path: C:UsersJohn
New Line
DPath: C:\Users\John\nNew Line
Attempts:
2 left
💡 Hint
Remember that \\ in double quotes prints a single backslash, and \n prints a newline.