From the course: Learning PHP
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using include and require
- [Instructor] There are two ways to include external files in PHP. They are with the built-in directives or functions, Include and Require. There is a small distinction made because Include and Require don't have the parentheses around them, though you could write them that way. They're not technically functions. They're more like statements that you're making. They both work the same way though, with the small difference that with Include, if the file doesn't exist, Include will throw a warning or non-terminating error, and Require we'll throw a compile error, which will stop the program from running. So let's say that we have two files, Index and Variables, both are in the same directory. What we can do is copy the variables from Index and paste them into the Variables dot PHP file. We still need the opening PHP tag here, and then we'll save that. And instead, we could say Require will require this because our…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
Organizing your code2m 45s
-
(Locked)
Using include and require4m 43s
-
(Locked)
include_once and require_once2m 46s
-
(Locked)
Namespacing3m 29s
-
(Locked)
Challenge: Build a simple templating system for the provided markup32s
-
(Locked)
Solution: Build a simple templating system for the provided markup7m 18s
-
-
-
-
-