dhmyers82 Posted February 4, 2015 Share Posted February 4, 2015 The text book I am using has 1 page on include files and no examples. I understand how to call the include file and that when I name it I should use the inc_ prefix... Where I am lost is what needs to be inside the include file? What can I omit from the file? Do I just write it like it is part of the .php file I am working on Example...I want to use a include file for a list of links. Starting File <html> <head> </head> <body> <?php> include 'links.php'; ?> </body> </html> Include File <nav> <ul> <li><a href="link1.htlm">Link 1</li> <li><a href="link2.htlm">Link 2</li> <li><a href="link3.htlm">Link 3</li> </ul> </nav> Do I need anything else in the include or would this work? Quote Link to comment Share on other sites More sharing options...
Solution NotionCommotion Posted February 4, 2015 Solution Share Posted February 4, 2015 You have it correct. Your narrative stated to use the "inc" extension such as links.inc, however, either php or inc will work (I originally used inc, but now just use php). I would also use require instead of include unless you want it to work if the file doesn't exist (can't see why you would ever want this). Most often, I recommend absolute paths (use include '/var/www/my_include_files/links.php'). You could also include PHP in the include file (just put tags around it). You might want to use a loop to create your list. Quote Link to comment Share on other sites More sharing options...
dhmyers82 Posted February 4, 2015 Author Share Posted February 4, 2015 for the HTML would I put all of it in the include file or would put part of it index file. <nav> <?php required foo.php ?> </nav> or how I had it to begin with. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 4, 2015 Share Posted February 4, 2015 for the HTML would I put all of it in the include file or would put part of it index file. or how I had it to begin with. Do what makes most sense to you, and what gives you the most flexibility. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.