PHP Tags and Embedding Syntax
Use opening/closing PHP tags and short echo syntax inside HTML.
Mixing PHP and HTML
PHP was designed to embed inside HTML files. When the server processes a .php file, everything between PHP tags is executed; everything else is sent to the browser as-is.
Standard PHP Tags
The standard opening and closing PHP tags:
<!DOCTYPE html>
<html><body>
<?php
$name = 'Alice';
echo 'Hello, ' . $name;
?>
<p>This is regular HTML.</p>
<?php
echo '<p>Back in PHP!</p>';
?>
</body></html>All lessons in this course
- PHP Tags and Embedding Syntax
- Dynamic HTML with PHP Loops
- Including and Requiring Files
- Template Pattern: Separating Logic from View