Jump to content

include files


dhmyers82
Go to solution Solved by NotionCommotion,

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.