Module 1 – Introduction to Web Development
Lesson
HTML and PHP Together
Mixing static and dynamic content
PHP is most often embedded in HTML templates. Outside <?php ?> blocks you write plain HTML; inside blocks you generate dynamic parts: product lists, logged-in user names, pagination. Alternatively, use the shorter echo syntax <?= $var ?> to output values. Organizing code into header.php, footer.php, and pages reduces duplication.
Best practice
- Keep logic (queries, validation) at the top of the file or in separate include files.
- Keep HTML readable – avoid deeply nested PHP blocks inside attributes.
- Use htmlspecialchars() when outputting user data in HTML.
Example flow
Load data from the database into an array, then in a foreach loop generate <tr> table rows.
<?php
$proizvodi = ["Monitor", "Tastatura", "Miš"];
?>
<ul>
<?php foreach ($proizvodi as $p): ?>
<li><?= htmlspecialchars($p) ?></li>
<?php endforeach; ?>
</ul>Working in the local environment
Create the folder htdocs/php-kurs inside XAMPP htdocs. Practice each new topic in a separate file (e.g. html-i-php-zajedno.php) to track your progress easily. Keep Developer Tools (F12) open – the Network and Console tabs speed up learning.
