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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.