0
0
PHPprogramming~5 mins

Escape sequences in strings in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an escape sequence in PHP strings?
An escape sequence is a way to include special characters in a string that would otherwise be hard to type or have special meaning, like new lines or quotes. It starts with a backslash (\).
Click to reveal answer
beginner
How do you write a newline character inside a PHP string?
Use the escape sequence \n inside double-quoted strings to add a new line.
Click to reveal answer
beginner
What escape sequence do you use to include a double quote inside a double-quoted PHP string?
Use \" to include a double quote inside a double-quoted string.
Click to reveal answer
intermediate
What happens if you use single quotes in PHP strings regarding escape sequences?
In single-quoted strings, only \\' and \\ are recognized as escape sequences. Others like \n are treated as normal characters.
Click to reveal answer
beginner
List three common escape sequences in PHP strings and their meanings.
\n = new line, \t = tab, \" = double quote inside double-quoted string.
Click to reveal answer
Which escape sequence adds a tab space in a PHP double-quoted string?
A\t
B\n
C\r
D\b
How do you write a backslash character inside a PHP string?
A\\
B\n
C\"
D\t
In PHP, which escape sequences work inside single-quoted strings?
ANone
B\\ and \' only
CAll escape sequences
D\n and \t
What will this PHP code output? echo "Hello\nWorld";
AHello\nWorld
BError
CHello World
DHello (new line) World
Which escape sequence inserts a carriage return in PHP strings?
A\t
B\n
C\r
D\b
Explain how escape sequences work in PHP strings and give examples.
Think about how to include special characters inside strings.
You got /3 concepts.
    Describe the difference between escape sequences in single-quoted and double-quoted PHP strings.
    Consider which escape sequences are processed in each string type.
    You got /3 concepts.