0
0
PHPprogramming~10 mins

Heredoc and nowdoc syntax 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 start a heredoc string with the identifier TEXT.

PHP
<?php
$heredoc = <<<[1]
This is a heredoc string.
TEXT;
?>
Drag options to blanks, or click blank then click option'
Atext
B'TEXT'
CTEXT
D"TEXT"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the identifier in heredoc start.
Using lowercase letters that don't match the closing label.
2fill in blank
medium

Complete the code to start a nowdoc string with the identifier DATA.

PHP
<?php
$nowdoc = <<<'[1]'
This is a nowdoc string.
DATA;
?>
Drag options to blanks, or click blank then click option'
ADATA
Bdata
C"DATA"
D'DATA'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for nowdoc.
Not matching the closing label with the starting identifier.
3fill in blank
hard

Fix the error in the heredoc closing label to properly end the string.

PHP
<?php
$text = <<<EOT
Hello, world!
[1];
?>
Drag options to blanks, or click blank then click option'
AEOT
B'EOT'
C"EOT"
DEot
Attempts:
3 left
💡 Hint
Common Mistakes
Indenting the closing label.
Using quotes around the closing label.
Changing the case of the closing label.
4fill in blank
hard

Fill both blanks to create a heredoc string that includes a variable $name.

PHP
<?php
$name = "Alice";
$message = <<<[1]
Hello, [2]!
[1];
?>
Drag options to blanks, or click blank then click option'
AGREETING
B$name
Cname
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the heredoc identifier.
Not using the $ sign before the variable inside heredoc.
5fill in blank
hard

Fill all three blanks to create a nowdoc string that includes the literal text $name without parsing.

PHP
<?php
$name = "Bob";
$text = <<<'[1]'
Hello, [2]!
[3];
?>
Drag options to blanks, or click blank then click option'
ADATA
B$name
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes around the nowdoc identifier.
Trying to parse variables inside nowdoc.