0
0
PHPprogramming~10 mins

String type (single vs double quotes) in PHP - Interactive Practice

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

Complete the code to create a string with single quotes.

PHP
$greeting = [1]Hello World[1];
Drag options to blanks, or click blank then click option'
A/
B"
C'
D`
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes when single quotes are required.
Using backticks which are for shell execution in PHP.
2fill in blank
medium

Complete the code to create a string with double quotes.

PHP
$name = [1]John[1];
Drag options to blanks, or click blank then click option'
A"
B'
C`
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes when double quotes are needed for variable parsing.
Using backticks which are not for strings.
3fill in blank
hard

Fix the error in the code to correctly print the variable inside the string.

PHP
echo [1]Hello, $user![1];
Drag options to blanks, or click blank then click option'
A/
B'
C`
D"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which print the variable name literally.
Using backticks which execute shell commands.
4fill in blank
hard

Fill both blanks to create a string that includes a variable without parsing it.

PHP
$text = [1]The variable is $var[2];
Drag options to blanks, or click blank then click option'
A'
B"
C`
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes which parse the variable.
Using mismatched quotes causing syntax errors.
5fill in blank
hard

Fill all three blanks to create a string with double quotes and escape the inner double quote.

PHP
$quote = [1]He said, [2]Hello![3] to me.[1];
Drag options to blanks, or click blank then click option'
A"
B\"
C'
D\'
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping inner double quotes causing syntax errors.
Using single quotes outside which don't allow escaping double quotes inside.