Summary - PHP basics
Combine tags, echo and comments to write your first PHP page.
Summary - PHP basics
In this group you learned the building blocks of PHP: tags (<?php ?>), output with echo, comments (//, #, /* */) and version info with phpinfo() / PHP_VERSION.
A PHP file starts with <?php. You print text with echo; every statement ends with ;. Comments explain your code and are ignored by PHP.
You can check the server configuration with phpinfo() and the version number with the PHP_VERSION constant.
Exercise Write a comment and print a greeting
Write a PHP block. Add a single-line // comment. Then use echo to print "Hello PHP"; add \n at the end of the line.
Show example solution
Write a // comment, then add echo "Hello PHP\n";.
Example solution:
<?php
// greeting
echo "Hello PHP\n";
Exercise phpinfo comment and version output
Write a PHP block. Include the word phpinfo() in a // comment. Then use echo to print "PHP 8.3"; add \n at the end of the line.
Show example solution
Write phpinfo in a // comment, then add echo "PHP 8.3\n";.
Example solution:
<?php
// phpinfo() gives info
echo "PHP 8.3\n";
Test yourself
-
Between which tags is PHP code written?
- <html></html>
- <?php ?>
- <js></js>
- <code></code>
Show answer
<?php ?> — Correct! PHP code is written between <?php ?> tags.
-
Complete the version comment
<?php ____ echo "PHP 8.3"; ?>Show answer
<?php // version info echo "PHP 8.3"; ?>