Assumewehaveastandardfooterfilecalled"footer.php",thatlookslikethis:
Toincludethefooterfileinapage,usetheincludestatement:
Example
Welcometomyhomepage!
Sometext.
Somemoretext.
Runexample?
Example2
Assumewehaveastandardmenufilecalled"menu.php":
AllpagesintheWebsiteshouldusethismenufile.Hereishowitcanbedone(weareusingaelementsothatthemenueasilycanbestyledwithCSSlater):
Example
Welcometomyhomepage!
Sometext.
Somemoretext.
Runexample?
Example3
Assumewehaveafilecalled"vars.php",withsomevariablesdefined:
Then,ifweincludethe"vars.php"file,thevariablescanbeusedinthecallingfile:
Example
Welcometomyhomepage!
Runexample?
PHPincludevs.require
TherequirestatementisalsousedtoincludeafileintothePHPcode.
However,thereisonebigdifferencebetweenincludeandrequire;whenafileisincludedwiththeincludestatementandPHPcannotfindit,thescriptwillcontinuetoexecute:
Example
Welcometomyhomepage!
Runexample?Ifwedothesameexampleusingtherequirestatement,theechostatementwillnotbeexecutedbecausethescriptexecutiondiesaftertherequirestatementreturnedafatalerror:
Example