© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_17

17. Importing Files

Mikael Olsson

(1)Hammarland, Finland

The same code often needs to be called on multiple pages. This can be done by first placing the code inside a separate file and then including that file using the include statement. This statement takes all the text in the specified file and includes it in the script, as if the code had been copied to that location. Just like echo, include is a special language construct and not a function, so parentheses should not be used.

<?phpinclude 'myfile.php';?>

When a file is included, parsing changes to HTML mode at the beginning of the target file and resumes PHP mode again at the end. For this reason, ...

Get PHP 7 Quick Scripting Reference, Second Edition 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.