Reusable components are a staple of modern front-end web development. On my simple PHP website, I wanted to build user interface pieces, and reuse them across multiple pages. When I was creating a new page for a newsletter signup form, I realized that I was repeating a lot of code for a contact form section that is displayed on almost every page.
Searching the code base for references to this particular HTML revealed ten instances that could be cleaned up.
In the new component file, I copy and paste my HTML and CSS code. Then, I go through each of the offending files, and replace the markup with a reference:
<?php include $_SERVER["DOCUMENT_ROOT"] . '/components/contact-section.php'; ?>