Week 2. Hello World (Includes)
Chapter 2
1. What Are Includes?
- Includes allow you to embed the contents of one PHP file into another.
- They are useful for reusing common elements like headers, footers, or navigation bars across multiple pages.
2. Why Use Includes?
- Consistency: You can maintain a uniform design for your website by centralizing shared components.
- Efficiency: Changes to shared components (e.g., updating a navigation menu) only need to be made once.
- Readability: Code becomes more modular and easier to manage.
- Error Reduction: Centralizing common code reduces the risk of duplication errors.
3. Key Differences Between include
and require
:
include
: Produces a warning if the file cannot be found but continues script execution.require
: Produces a fatal error and stops script execution if the file cannot be found.
Note: Using PHP includes effectively promotes clean, efficient, and maintainable code.
Note: Using PHP includes effectively promotes clean, efficient, and maintainable code.
Assignment
- Hello World
- Hello World with show code
- Hello World with include
- Your Assignment is to get "Your Main Page with Examples" web page up and running using "header" and "footer" includes. The purpose of this exercise is to make your Example web page easy to add assignments and keep assignments in order for easy viewing and grading.