A basic example of using echo
to create output with PHP.
This tutorial will review how to use the PHP echo
command to create output. Here is a basic sample of using echo
to output a "Hello World" message:
<?php
echo '<p>Hello World!</p>';
?>
-
Open up a new file and name it output.php.
-
Copy the content from sample.html and paste it into your new PHP file.
-
Convert the HTML code in between the
<body>
and</body>
from HTML to PHP. -
For example the first line of HTML in the
<body>
tag is:<h1>PHP and Creating Output</h1>
After this line is converted to PHP it will be something like this:
<?php echo '<h1>PHP and Creating Output</h1>'; ?>
Hint: Convert each line of HTML to PHP one line at a time. Test your PHP after converting each line of code.
Full tutorial URL:
https://codeadam.ca/learning/php-output.html
- Visual Studio Code or Brackets (or any code editor)
- Filezilla (or any FTP program)