0
0
PHPprogramming~20 mins

PHP tags and embedding in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Embedding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of PHP embedded in HTML
What is the output of this PHP code embedded in HTML when accessed via a browser?
PHP
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<?php echo "Hello, " . "World!"; ?>
</body>
</html>
AHello,World!
B<?php echo "Hello, " . "World!"; ?>
CHello, World!
DSyntax Error
Attempts:
2 left
💡 Hint
PHP code inside tags runs on the server and outputs text to the page.
Predict Output
intermediate
2:00remaining
Short PHP tags output
What will this code output if short PHP tags are enabled on the server?
PHP
<html>
<body>
<?= "Quick output" ?>
</body>
</html>
ASyntax Error
B<?= "Quick output" ?>
CQuick output<?= "Quick output" ?>
DQuick output
Attempts:
2 left
💡 Hint
is a shortcut for if enabled.
Predict Output
advanced
2:00remaining
Output with mixed PHP and HTML
What is the output of this code?
PHP
<html>
<body>
<?php
for ($i = 1; $i <= 3; $i++) {
    ?>
    <p>Number <?= $i ?></p>
<?php
}
?>
</body>
</html>
A<p>Number <?= $i ?></p><p>Number <?= $i ?></p><p>Number <?= $i ?></p>
B<p>Number 1</p><p>Number 2</p><p>Number 3</p>
CSyntax Error
DNumber 1Number 2Number 3
Attempts:
2 left
💡 Hint
PHP code can switch in and out of HTML mode inside loops.
Predict Output
advanced
2:00remaining
PHP tags inside HTML attributes
What will be the output of this code?
PHP
<html>
<body>
<a href="page.php?id=<?php echo 5; ?>">Link</a>
</body>
</html>
A<a href="page.php?id=5">Link</a>
B<a href="page.php?id=<?php echo 5; ?>">Link</a>
C<a href="page.php?id=">Link</a>
DSyntax Error
Attempts:
2 left
💡 Hint
PHP code inside attribute values outputs the result directly.
Predict Output
expert
2:00remaining
Output with nested PHP tags and whitespace
What is the exact output of this code including spaces and newlines?
PHP
<html>
<body>
<?php
echo "Start";
?>

<?php
 echo " ";
?>
End
</body>
</html>
A
Start 
End
BStartEnd
C
Start
End
DSyntax Error
Attempts:
2 left
💡 Hint
PHP code outputs text; whitespace outside PHP tags is preserved.