0
0
PHPprogramming~10 mins

Escape sequences in strings in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a new line using an escape sequence.

PHP
<?php
echo "Hello[1]World!";
?>
Drag options to blanks, or click blank then click option'
A\n
B\t
C\r
D\\
Attempts:
3 left
💡 Hint
Common Mistakes
Using \t which adds a tab space instead of a new line.
Using \\ which prints a backslash.
2fill in blank
medium

Complete the code to include a tab space between words.

PHP
<?php
echo "Hello[1]World!";
?>
Drag options to blanks, or click blank then click option'
A\t
B\n
C\r
D\\
Attempts:
3 left
💡 Hint
Common Mistakes
Using \n which adds a new line instead of a tab.
Using \\ which prints a backslash.
3fill in blank
hard

Fix the error in the code to correctly print a backslash character.

PHP
<?php
echo "This is a backslash: [1]";
?>
Drag options to blanks, or click blank then click option'
A\t
B\\
C\n
D\
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single backslash which causes an error or unexpected output.
Using \n or \t which print new line or tab instead.
4fill in blank
hard

Fill both blanks to print a double quote inside a string.

PHP
<?php
echo "She said: [1]Hello[2]";
?>
Drag options to blanks, or click blank then click option'
A\"
B\n
C"
D\t
Attempts:
3 left
💡 Hint
Common Mistakes
Using unescaped double quotes which break the string.
Using single quotes which do not work inside double-quoted strings.
5fill in blank
hard

Fill all three blanks to print a path with backslashes and a new line.

PHP
<?php
echo "C:[1]Users[2]Documents[3]";
?>
Drag options to blanks, or click blank then click option'
A\\
B\n
C/
D\t
Attempts:
3 left
💡 Hint
Common Mistakes
Using single backslashes which cause errors.
Using forward slashes instead of backslashes.
Forgetting to add a new line escape sequence.