Challenge - 5 Problems
PHP Embedding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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>
Attempts:
2 left
💡 Hint
PHP code inside tags runs on the server and outputs text to the page.
✗ Incorrect
The PHP code concatenates two strings and outputs 'Hello, World!'. The browser sees only the output, not the PHP code.
❓ Predict Output
intermediate2: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>Attempts:
2 left
💡 Hint
= ... ?> is a shortcut for if enabled.
✗ Incorrect
The short echo tag outputs the string directly if enabled. Otherwise, it may show raw code or error.
❓ Predict Output
advanced2: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>
Attempts:
2 left
💡 Hint
PHP code can switch in and out of HTML mode inside loops.
✗ Incorrect
The loop runs 3 times, outputting a paragraph with the current number each time.
❓ Predict Output
advanced2: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>Attempts:
2 left
💡 Hint
PHP code inside attribute values outputs the result directly.
✗ Incorrect
The PHP code outputs 5, so the href attribute becomes 'page.php?id=5'.
❓ Predict Output
expert2: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>
Attempts:
2 left
💡 Hint
PHP code outputs text; whitespace outside PHP tags is preserved.
✗ Incorrect
The first PHP block outputs 'Start', then a newline and space outside PHP tags, then the second PHP block outputs a space, then 'End'.