Jump to content

include files


dhmyers82

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/294372-include-files/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/294372-include-files/#findComment-1504850
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.