Using External Files

To this point, every script in the book has consisted of a single file that contains all of the required code. But as you develop more complex Web sites, you’ll see that this methodology has many limitations. PHP can readily make use of external files, which allows you to divide your scripts into their distinct parts. Frequently you will use external files to extract your HTML from your PHP or to separate out commonly used processes.

PHP has four functions for using external files: include(), include_once(), require(), and require_once(). To use them, your PHP script would have a line like

include_once("filename.php");
require('/path/to/filename.html');

The use of one of these functions has the end result of taking all ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.